How to use the asp.net Random function

Source: Internet
Author: User
Tags static class time in milliseconds

The root cause of random number calculation is the number of random seeds. I used to use the time in milliseconds, but if the time is too fast, it will lead to the same number.

If the number of calls is added as a parameter:

Asp tutorial. net application

<% @ 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 (1, 100 ));
}
</Script>

Test instance

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 ());
    }
}

Official website instances

Byte [] bytes1 = new byte [2, 100];
Byte [] bytes2 = new byte [1, 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 ();
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.