BCL mscorlib [00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 ] 1.0.5000.0 2.0.0.0 4.0.0.0 All public static members of this type are safe for multithreaded operations. No instance members are guaranteed to be thread safe. System.Object System.Runtime.InteropServices.ComVisible(true)

Pseudo-random numbers are chosen with equal probability from a finite set of numbers. The chosen numbers are not completely random because a definite mathematical algorithm is used to select them, but they are sufficiently random for practical purposes. The current implementation of the class is based on Donald E. Knuth's subtractive random number generator algorithm. For more information, see D. E. Knuth. "The Art of Computer Programming, volume 2: Seminumerical Algorithms". Addison-Wesley, Reading, MA, second edition, 1981.

The random number generation starts from a seed value. If the same seed is used repeatedly, the same series of numbers is generated. One way to produce different sequences is to make the seed value time-dependent, thereby producing a different series with each new instance of . By default, the parameterless constructor of the class uses the system clock to generate its seed value, while its parameterized constructor can take an value based on the number of ticks in the current time. However, because the clock has finite resolution, using the parameterless constructor to create different objects in close succession creates random number generators that produce identical sequences of random numbers. The following example illustrates that two objects that are instantiated in close succession generate an identical series of random numbers.

code reference: System.Random#1

This problem can be avoided by creating a single Random object rather than multiple ones.

To improve performance, create one object to generate many random numbers over time, instead of repeatedly creating a new objects to generate one random number.

To generate a cryptographically secure random number suitable for creating a random password, for example, use a class derived from such as .

Represents a pseudo-random number generator, a device that produces a sequence of numbers that meet certain statistical requirements for randomness.

- Constructor
  1.0.5000.0
  2.0.0.0
  4.0.0.0

  The distribution of the generated numbers is uniform; each number is equally likely to be returned.

  The default seed value is derived from the system clock and has finite resolution. As a result, different objects that are created in close succession by a call to the default constructor will have identical default seed values and, therefore, will produce identical sets of random numbers. This problem can be avoided by using a single object to generate all random numbers. You can also work around it by modifying the seed value returned by the system clock and then explicitly providing this new seed value to the constructor. For more information, see the constructor.

  Initializes a new instance of the class, using a time-dependent default seed value.

  0
- Constructor
  1.0.5000.0
  2.0.0.0
  4.0.0.0

  The following example demonstrates using a bitwise complement operation to obtain different random numbers using a time-dependent seed value on high performance systems.

  using System; class RandomTest { public static void Main() { Random rand1 = new Random(); Random rand2 = new Random(Environment.TickCount); Console.WriteLine("The random number is {0}",rand1.Next()); Console.WriteLine("The random number is {0}",rand2.Next());

  Random rdm1 = new Random(unchecked(Environment.TickCount)); Random rdm2 = new Random(~unchecked(Environment.TickCount)); Console.WriteLine("The random number is {0}",rdm1.Next()); Console.WriteLine("The random number is {0}",rdm2.Next()); } }

  The output is

  The random number is 1990211954

  The random number is 1990211954

  The random number is 1990211954

  The random number is 964628126

  Providing an identical seed value to different objects causes each instance to produce identical sequences of random numbers.

  If your application requires different random number sequences, invoke this constructor repeatedly with different seed values. One way to produce a unique seed value is to make it time-dependent. For example, derive the seed value from the system clock. However, the system clock might not have sufficient resolution to provide different invocations of this constructor with a different seed value. This results in random number generators that generate identical sequences of pseudo-random numbers, as illustrated by the first two objects in the following example. To prevent this, apply an algorithm to differentiate the seed value in each invocation, or call the method to ensure that you provide each constructor with a different seed value.

  code reference: System.Random.Ctor#4

  Initializes a new instance of the class, using the specified seed value.

  A number used to calculate a starting value for the pseudo-random number sequence. If a negative number is specified, the absolute value of the number is used.
  0
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Int32

  The following example demonstrates using the method. The output generated by this example will vary.

  `using System; class RandomTest { public static void Main() { Random rand1 = new Random(); for (int i = 0; i<10;i++) Console.WriteLine("The random number is {0}",rand1.Next()); } }`

  The output is

  The random number is 1544196111

  The random number is 181749919

  The random number is 1045210087

  The random number is 1073826097

  The random number is 1533078806

  The random number is 1083151645

  The random number is 569083504

  The random number is 1711370568

  The random number is 578178313

  The random number is 409444742

  generates a random number whose value ranges from zero to less than . To generate a random number whose value ranges from zero to some other positive number, use the method overload. To generate a random number within a different range, use the method overload.

  Returns a nonnegative random integer.

  A 32-bit signed integer greater than or equal to zero and less than .

  0
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Int32 ``

  As described above.

  Override this method to customize the algorithm used to generate the return value.

  Use this method to generate a psuedo-random number less than the specified maximum value.

  is less than zero.

  Returns a nonnegative random integer that is less than the specified maximum.

  A 32-bit signed integer greater than or equal to zero, and less than ; that is, the range of return values ordinarily includes zero but not . However, if equals zero, is returned.

  The exclusive upper bound of the random number to be generated. must be greater than or equal to zero. 0
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Int32 `` `` is greater than .

  Unlike the other overloads of the method, which return only non-negative values, this method can return a negative random integer.

  Returns a random integer that is within a specified range.

  A 32-bit signed integer greater than or equal to and less than ; that is, the range of return values includes but not . If equals , is returned.

  The inclusive lower bound of the random number returned. The exclusive upper bound of the random number returned. must be greater than or equal to . 0
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Void `` is a reference.

  Each element of the array of bytes is set to a random number greater than or equal to zero, and less than or equal to .

  To generate a cryptographically secured random number suitable for creating a random password, for example, use a method such as .

  Fills the elements of a specified array of bytes with random numbers.

  An array of bytes to contain random numbers. 0
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Double

  This method is the public version of the protected method, .

  Returns a random floating-point number between 0.0 and 1.0.

  A double-precision floating point number greater than or equal to 0.0, and less than 1.0.

  1
  ExtendedNumerics
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Double

  To produce a different random distribution or a different random number generator principle, derive a class from the class and override the method.

  The method is protected, which means that it is accessible only within the class and its derived classes. To generate a random number between 0 and 1 from a instance, call the method.

  Returns a random floating-point number between 0.0 and 1.0.

  A double-precision floating point number greater than or equal to 0.0, and less than 1.0.

0