日期:2014-05-17 浏览次数:20500 次
public string RandomNum(int n) // { string strchar = "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[] VcArray = strchar.Split(','); string VNum = ""; // int temp = -1; //记录上次随机数值,尽量避免产生几个一样的随机数 //采用一个简单的算法以保证生成随机数的不同 Random rand = new Random(); for (int i = 1; i < n + 1; i++) { if (temp != -1) { rand = new Random(i * temp * unchecked((int)DateTime.Now.Ticks)); } int t = rand.Next(61); if (temp != -1 && temp == t) { return RandomNum(n);——————这个递归不怎么明白 } temp = t; VNum += VcArray[t]; } return VNum;//返回生成的随机数 }