asp.net Random随机函数使用方法
随机数计算的根源,就是随机种子数,我原来用的是时间的毫秒,但是时间太快的话,就会导致取出的数字一样
如果加入调用次数作为参数呢:
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();
}
补充:asp.net教程,.Net开发