标签:
#region 获取随机字符串
//digit 最终返回的字符串的长度
public static string BuildCode(int digit)
{
StringBuilder resultCode = new StringBuilder();
Random ran = new Random(GetRandomSeed());
for (int i = 0; i < digit; i++)
{
resultCode.Append(("0123456789").Substring(ran.Next(0, 10), 1));
}
string resultCode1 = resultCode.ToString();
return resultCode1;
}
static int GetRandomSeed()
{
byte[] bytes = new byte[4];
System.Security.Cryptography.RNGCryptoServiceProvider rng = new System.Security.Cryptography.RNGCryptoServiceProvider();
rng.GetBytes(bytes);
return BitConverter.ToInt32(bytes, 0);
}
#endregion
标签:
原文地址:http://www.cnblogs.com/zxk3113/p/5231947.html