注册 登录
编程论坛 ASP.NET技术论坛

[求助]随机数输出的问题

重在参与 发布于 2007-10-23 16:35, 508 次点击

string allchar = "0,1,2,3,4,5,6,7,8,9";
string[] allchararray = allchar.Split(',');
for (int i = 0; i < allchararray.Length; i++)
{
Random rnd = new Random(unchecked((int)DateTime.Now.Ticks * i));

Response.Write(rnd.Next() + " <br > ");
}

这是我写的代码,我只想随机输出0-9其中的一个数,请问应该怎么做啊?

7 回复
#2
sxzxwxf222007-10-23 16:45

Random rnd = new Random()
这个东西要放在for外面

#3
sxzxwxf222007-10-23 16:46

前几天我回baidu上一个问题时写的
跟你的一样
public string Rand()
{
string all = "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,W,X,Y,Z";
string[] allChar = all.Split(',');
string result = "";
Random rand = new Random();
for (int i = 0; i < 15; i++)
{

result += allChar[rand.Next(35)];
}
return result ;
}

#4
jxnuwy042007-10-24 00:44
随机输出10个0-9的数
System.Random r = new Random(0);
int[] a = new int[10];
for (int i = 0; i < 10; i++)
{
a[i] = r.Next(0, 9);
Console.Write(a[i] + "\n");
}
#5
重在参与2007-10-24 11:40

楼上的,你这每次输出的都是一样的啊

#6
bygg2007-10-24 12:39
输出其中的一个数?
Random rdom = new Random();
rdom.Next(0,9);
#7
jxnuwy042007-10-24 13:15
以下是引用重在参与在2007-10-24 11:40:50的发言:

楼上的,你这每次输出的都是一样的啊

每次输出的不一样,我试过了。会随机输出10个数,当然里面肯定会有重复的了!

#8
重在参与2007-10-24 16:01
谢谢各位
1