C# Class SecurityDriven.Inferno.CryptoRandom

Represents a *thread-safe*, cryptographically-strong, pseudo-random number generator (based on RNGCryptoServiceProvider). 2-4 times slower than System.Random (would've been 150 times slower without buffering).
Inheritance: System.Random
Mostra file Open project: sdrapkin/SecurityDriven.Inferno

Public Methods

Method Description
Next ( ) : int

Returns a nonnegative random number.

Next ( int maxValue ) : int

Returns a nonnegative random number less than the specified maximum.

Next ( int minValue, int maxValue ) : int

Returns a random number within a specified range.

NextBytes ( int count ) : byte[]

Returns a new count-sized byte array filled with random bytes.

NextBytes ( byte buffer ) : void

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

NextBytes ( byte buffer, int offset, int count ) : void

Fills the specified byte array with a cryptographically strong random sequence of values.

NextDouble ( ) : double

Returns a random number between 0.0 and 1.0.

NextLong ( ) : long

Returns a nonnegative random number.

NextLong ( long maxValue ) : long

Returns a nonnegative random number less than the specified maximum.

NextLong ( long minValue, long maxValue ) : long

Returns a random number within a specified range.

Private Methods

Method Description
CryptoRandom ( ) : System
GetRandomUInt ( ) : uint

Gets one random unsigned 32bit integer in a thread safe manner.

GetRandomULong ( ) : ulong

Gets one random unsigned 64bit integer in a thread safe manner.

NextBytesInternal ( ArraySegment bufferSegment ) : void
SanityCheck ( ) : void

Method Details

Next() public method

Returns a nonnegative random number.
public Next ( ) : int
return int

Next() public method

Returns a nonnegative random number less than the specified maximum.
/// is less than zero. ///
public Next ( int maxValue ) : int
maxValue int The exclusive upper bound of the random number to be generated. must be greater than or equal to zero.
return int

Next() public method

Returns a random number within a specified range.
/// is greater than . ///
public Next ( int minValue, int maxValue ) : int
minValue int The inclusive lower bound of the random number returned.
maxValue int The exclusive upper bound of the random number returned. must be greater than or equal to .
return int

NextBytes() public method

Returns a new count-sized byte array filled with random bytes.
public NextBytes ( int count ) : byte[]
count int Array length.
return byte[]

NextBytes() public method

Fills the elements of a specified array of bytes with random numbers.
/// is null. ///
public NextBytes ( byte buffer ) : void
buffer byte The array to fill with cryptographically strong random bytes.
return void

NextBytes() public method

Fills the specified byte array with a cryptographically strong random sequence of values.
/// is null. ///
public NextBytes ( byte buffer, int offset, int count ) : void
buffer byte An array of bytes to contain random numbers.
offset int
count int Number of bytes to generate (must be lte buffer.Length).
return void

NextDouble() public method

Returns a random number between 0.0 and 1.0.
public NextDouble ( ) : double
return double

NextLong() public method

Returns a nonnegative random number.
public NextLong ( ) : long
return long

NextLong() public method

Returns a nonnegative random number less than the specified maximum.
/// is less than zero. ///
public NextLong ( long maxValue ) : long
maxValue long The exclusive upper bound of the random number to be generated. must be greater than or equal to zero.
return long

NextLong() public method

Returns a random number within a specified range.
/// is greater than . ///
public NextLong ( long minValue, long maxValue ) : long
minValue long The inclusive lower bound of the random number returned.
maxValue long The exclusive upper bound of the random number returned. must be greater than or equal to .
return long