Generation of random numbers (ASP. NET, C #)

Source: Internet
Author: User

Random class namespace:
System. Object
System. Random

A pseudo-random number generator, a device that can generate digital sequences that meet certain random statistical requirements.

Remarks

A pseudo-random number is selected from a finite number with the same probability. The selected numbers are not completely random because they use a definite math.AlgorithmBut from a practical point of view, the degree of randomness is enough.

The random number is generated starting from the seed value. If the same seed is used repeatedly, the same digital series is generated. One way to generate different sequences is to associate the seed values with time, so that different generations are generated for each new instance of random.

To improve performance, create a random so that many random numbers can be generated over time, instead of repeatedly creating a new random to generate a random number.

Method

1: Next

The reload list returns a non-negative random number.
[Visual Basic] overloads public overridable function next () as integer
[C #] Public Virtual int next ();

Returns a nonnegative random number that is less than the specified maximum value.
[Visual Basic] overloads public overridable function next (integer) as integer
[C #] Public Virtual int next (INT );

Returns a random number within the specified range.
[Visual Basic] overloads public overridable function next (integer, integer) as integer
[C #] Public Virtual int next (INT, INT );

2: nextdouble

Returns a random number between 0.0 and 1.0.
[Visual Basic] public overridable function nextdouble () as double
[C #] Public Virtual double nextdouble ();

3: nextbytes

Fill in the elements of the specified byte array with a random number.

Example:
Random RND = new random ();
Byte [] B = new byte [10];
RND. nextbytes (B );
Console. writeline ("the random bytes are :");
For (INT I = 0; I <10; I ++ ){
Console. Write (I );
Console. Write (":");
Console. writeline (B [I]);
}

 

this article from the csdn blog, reprinted please indicate the source: http://blog.csdn.net/johnsonTj/articles/317712.aspx

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.