C#生成随机验证码
要求:要求返回一个验证码,并且不能同时存在容易混淆的0和Q;每个字母取得的概率要相同。
View Code1 private static string CreateCode(int count) 2 { 3 string code = "0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z"; 4 string[] keyCode = code.Split(','); 5 string validateCode = string.Empty; 6 Random rand = new Random(); 7 do 8 { 9 validateCode = string.Empty;10 for (int i = 0; i < count; i++)11 {12 string s = keyCode[rand.Next(0, 35)];13 validateCode += s;14 }15 }16 while ((validateCode.Contains("0") && validateCode.Contains("O")));17 return validateCode;18 }
TAG: