Table of Contents

Class Random

Namespace
System
Assembly
mscorlib.dll

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

public class Random
Inheritance
Random
Inherited Members
Extension Methods

Remarks

Depending on the platform it can be a software dependent pseudo-random generator algorithm or a hardware random generator providing true random numbers.

Constructors

Random()

Initializes a new instance of the Random class. If the provider is algorithm based the initialisation is performed using a time- dependent default seed value.

public Random()

Random(int)

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

public Random(int seed)

Parameters

seed int

A number used to calculate a starting value for the pseudo-random number sequence.

Methods

Next()

Returns a nonnegative random number.

public virtual int Next()

Returns

int

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

Next(int)

Returns a nonnegative random number less than the specified maximum.

public virtual int Next(int maxValue)

Parameters

maxValue int

The exclusive upper bound of the random number to be generated. maxValue must be greater than or equal to zero.

Returns

int

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

NextBytes(byte[])

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

public virtual void NextBytes(byte[] buffer)

Parameters

buffer byte[]

An array of bytes to contain random numbers.

NextDouble()

Returns a random number between 0.0 and 1.0.

public virtual double NextDouble()

Returns

double

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