标签:
//生成随机字母数字组合 public static string CreateRandom(int codeCount) { string allChar = "2,3,4,5,6,7,8,9,a,b,c,d,e,f,g,h,i,j,k,m,n,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,J,K,L,M,N,P,Q,R,S,T,U,V,W,X,Y,Z"; string[] allCharArray = allChar.Split(‘,‘); string randomCode = ""; int temp = -1; Random random = new Random(); for (int i = 0; i < codeCount; i++) { if (temp != -1) { random = new Random(i * temp * (int)DateTime.Now.Ticks); } int t = random.Next(35); if (temp == t) { return CreateRandom(codeCount); } temp = t; randomCode += allCharArray[temp]; } return randomCode; }
codeCount代表需要生成的字符串长度
标签:
原文地址:http://www.cnblogs.com/huangfenggu/p/4449678.html