Random number generation (ASP.NET, C #)

xiaoxiao2021-03-06  18

Random Category Space: System.Object System.random

Indicates a pseudo random number generator, an apparatus capable of generating a digital sequence that meets some random statistics requirements.

Note

The pseudo-random number is selected from a limited number of numbers with the same probability. The selected number does not have complete randomness because they are selected by a determined mathematical algorithm, but from a practical point of view, its randomness is sufficient.

The random number is started from the seed value. If the same seed is repeated, the same digital series is generated. One way to produce different sequences is to cause seed values ​​to time, so that each new instance of Random produces different series.

To improve performance, create a random so that over time can generate a lot of random numbers, instead of re-establishing random to generate a random number.

method

1: Next

The overload list returns a non-negative random number. [Visual Basic] overloads public overridable function next () AS INTEGER [C #] public virtual int next ();

Returns a non-negative random number smaller than the specified maximum. [Visual Basic] Overloads Public Overridable Function next (Integer) AS Integer [C #] Public Virtual Int Next (int);

Returns a random number within a 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 the elements of the specified byte array with random numbers.

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

转载请注明原文地址:https://www.9cbs.com/read-48152.html

New Post(0)