//调用GetRandomString()方法,里面的参数为int类型
private static int getNewSeed()
{
byte[] rndBytes = new byte[4];
System.Security.Cryptography.RNGCryptoServiceProvider rng = new System.Security.Cryptography.RNGCryptoServiceProvider();
rng.GetBytes(rndBytes);
return BitConverter.ToInt32(rndBytes, 0);
}
static public string GetRandomString(int len)
{
string s = "0123456789";//在此处也可以加字母A——Z
string reValue = string.Empty;
Random rnd = new Random(getNewSeed());
while (reValue.Length < 10)
{
string s1 = s[rnd.Next(0, s.Length)].ToString();
if (reValue.IndexOf(s1) == -1) reValue += s1;
}
return reValue;
}