随机生成6位字符，求解

0
[已解决问题] 解决于 2012-09-03 23:26

JeffQing | 初学一级 | 园豆：148

0
`这样就好了，自己用的生成验证码的方法`
```/// <summary>
/// 得到随机字符串
/// </summary>
/// <returns></returns>
public string GetRan()
{
Random r = new Random();
string str = "";
for (int q = 0; q < 6; q++)
{
int i = r.Next(48, 122);
if ((i > 57 && i < 65) || (i > 90 && i < 97))
{
i = GetNewRandom();
}
char ww = (char)i;
str += ww.ToString();

}
return str;
}
public int GetNewRandom()
{
Random r = new Random();
int i = r.Next(48, 122);
if ((i > 57 && i < 65) || (i > 90 && i < 97))
{
GetNewRandom();
}
return i;
}```

2
```public static string CreateRandomCode(int codeCount)
{
string allChar = @"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,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";
string[] allCharArray = allChar.Split(',');
string randomCode = "";

Random rand = new Random();
for (int i = 0, l = allCharArray.Length; i < codeCount; i++)
{
rand = new Random(i * (int)DateTime.Now.Ticks);
int t = rand.Next(0, l);
randomCode += allCharArray[t];
}
return randomCode;
}```

artwl | 园豆：16736 (专家六级) | 2012-07-27 21:45

您需要登录以后才能回答，未注册用户请先注册