#region 生成随机字符串
/// <summary>
/// 生成随机字符串
/// </summary>
/// <param name="codeCount"></param>
/// <param name="allChar"></param>
/// <returns></returns>
public static string CreateRandomCode(int codeCount)
{
//验证码中的出现的字符,避免了一些容易混淆的字符。
string allChar = "A,B,C,D,E,F,G,H,J,K,M,N,P,Q,R,S,T,U,W,X,Y";
string[] allCharArray = allChar.Split(‘,‘);
string randomCode = "";
int temp = -1;
bool breCreate = (codeCount < 6 && allCharArray.Length > 15);
Random rand = new Random();
for (int i = 0; i < codeCount; i++)
{
if (temp != -1)
{
rand = new Random(i * temp * ((int)DateTime.Now.Ticks));
}
int t = rand.Next(allCharArray.Length);
if (temp == t && breCreate)
{
return CreateRandomCode(codeCount);
}
temp = t;
randomCode += allCharArray[t];
}
return randomCode;
}
#endregion