隨機數計算的根源,就是隨機種子數,我原來用的是時間的毫秒,但是時間太快的話,就會導致取出的數字一樣
如果加入調用次數作為參數呢:
asp教程.net中應用
<%@ page language="c#" contenttype="text/html" responseencoding="gb2312" %>
<script runat="server">
void page_load(object sender,eventargs e){
random objrandom=new random();
label_1.text=convert.tostring(objrandom.next(100));
}
</script>
測試執行個體
public static class getint
{
public static int c;
public static int getone()
{
c++;
random ran = new random(datetime.now.millisecond + c);
return ran.next(0, getarg.getmax());
}
}
官網執行個體
byte[] bytes1 = new byte[100];
byte[] bytes2 = new byte[100];
random rnd1 = new random();
random rnd2 = new random();
rnd1.nextbytes(bytes1);
rnd2.nextbytes(bytes2);
console.writeline("first series:");
for (int ctr = bytes1.getlowerbound(0);
ctr <= bytes1.getupperbound(0);
ctr++) {
console.write("{0, 5}", bytes1[ctr]);
if ((ctr + 1) % 10 == 0) console.writeline();
}
console.writeline();
console.writeline("second series:");
for (int ctr = bytes2.getlowerbound(0);
ctr <= bytes2.getupperbound(0);
ctr++) {
console.write("{0, 5}", bytes2[ctr]);
if ((ctr + 1) % 10 == 0) console.writeline();
}