生成随机数有很多方法,如果php教程 mt_rand,rand asp教程 等。下面来看一款c随机生成方法。
public string rndnum(int vcodenum)
3 {
4 string vchar = "0,1,2,3,4,5,6,7,8,9";
5 string[] vcarray = vchar.split(new char[] { ',' });
6 string vnum = "";
7 //int temp = -1;
8 random rand = new random();
9 for (int i = 1; i < vcodenum + 1; i++)
10 {
11 int t = rand.next(10);
12 vnum += vcarray[t];
13 }
14 return vnum;
15 }
16 调用:string str = rndnum(4)