private string RndNum(int VcodeNum)
{
string Vchar = "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,h,e,l,l,o,h,i,l,l";
string[] VcArray = Vchar.Split(',');
string VNum = "";
Random rdm = new Random(unchecked((int)DateTime.Now.Ticks));
for (int i = 0; i < VcodeNum; i++)
{
VNum += VcArray[rdm.Next(0, 61)];
}
return VNum;
}
Split(',')用,分隔
VcodeNum 為產生的位數
Ticks為long型
Random(unchecked((int)DateTime.Now.Ticks)) // long型轉換為int型,因為會報錯,所以用unchecked不檢查
rdm.Next(0, 61) 從第0個到第61個 隨即取數,即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