C# Class OpenTK.MersenneTwister

Generates pseudo-random numbers using the Mersenne Twister algorithm.
Inheritance: System.Random
Mostrar archivo Open project: smalld/particle_system

Public Methods

Method Description
MersenneTwister ( ) : System

Creates a new pseudo-random number generator with a default seed.

new System.Random().Random.Next() is used for the seed.

MersenneTwister ( Int32 seed ) : System

Creates a new pseudo-random number generator with a given seed.

Next ( ) : Int32

Returns the next pseudo-random Int32.

Next ( Int32 maxValue ) : Int32

Returns the next pseudo-random Int32 up to maxValue.

Next ( Int32 minValue, Int32 maxValue ) : Int32

Returns the next pseudo-random Int32 at least minValue and up to maxValue.

NextBytes ( Byte buffer ) : void

Fills a buffer with pseudo-random bytes.

NextDouble ( ) : Double

Returns the next pseudo-random Double value.

There are two common ways to create a double floating point using MT19937: using GenerateUInt32 and dividing by 0xFFFFFFFF + 1, or else generating two double words and shifting the first by 26 bits and adding the second.

In a newer measurement of the randomness of MT19937 published in the journal "Monte Carlo Methods and Applications, Vol. 12, No. 5-6, pp. 385 – 393 (2006)" entitled "A Repetition Test for Pseudo-Random Number Generators", it was found that the 32-bit version of generating a double fails at the 95% confidence level when measuring for expected repetitions of a particular number in a sequence of numbers generated by the algorithm.

Due to this, the 53-bit method is implemented here and the 32-bit method of generating a double is not. If, for some reason, the 32-bit method is needed, it can be generated by the following: (Double)NextUInt32() / ((UInt64)UInt32.MaxValue + 1);

NextDouble ( System.Boolean includeOne ) : Double

Returns a pseudo-random number greater than or equal to zero, and either strictly less than one, or less than or equal to one, depending on the value of the given parameter.

NextDoublePositive ( ) : Double

Returns a pseudo-random number greater than 0.0 and less than 1.0.

NextSingle ( ) : System.Single

Returns a pseudo-random number between 0.0 and 1.0.

NextSingle ( System.Boolean includeOne ) : System.Single

Returns a pseudo-random number greater than or equal to zero, and either strictly less than one, or less than or equal to one, depending on the value of the given boolean parameter.

NextSinglePositive ( ) : System.Single

Returns a pseudo-random number greater than 0.0 and less than 1.0.

NextUInt32 ( ) : UInt32

Returns the next pseudo-random UInt32.

NextUInt32 ( UInt32 maxValue ) : UInt32

Returns the next pseudo-random UInt32 up to maxValue.

NextUInt32 ( UInt32 minValue, UInt32 maxValue ) : UInt32

Returns the next pseudo-random UInt32 at least minValue and up to maxValue.

Protected Methods

Method Description
GenerateUInt32 ( ) : UInt32

Generates a new pseudo-random UInt32.

Private Methods

Method Description
compute53BitRandom ( Double translate, Double scale ) : Double
init ( UInt32 seed ) : void
temperingShiftL ( UInt32 y ) : UInt32
temperingShiftS ( UInt32 y ) : UInt32
temperingShiftT ( UInt32 y ) : UInt32
temperingShiftU ( UInt32 y ) : UInt32

Method Details

GenerateUInt32() protected method

Generates a new pseudo-random UInt32.
protected GenerateUInt32 ( ) : UInt32
return System.UInt32

MersenneTwister() public method

Creates a new pseudo-random number generator with a default seed.
new System.Random().Random.Next() is used for the seed.
public MersenneTwister ( ) : System
return System

MersenneTwister() public method

Creates a new pseudo-random number generator with a given seed.
public MersenneTwister ( Int32 seed ) : System
seed System.Int32 A value to use as a seed.
return System

Next() public method

Returns the next pseudo-random Int32.
public Next ( ) : Int32
return System.Int32

Next() public method

Returns the next pseudo-random Int32 up to maxValue.
/// When < 0. ///
public Next ( Int32 maxValue ) : Int32
maxValue System.Int32 The maximum value of the pseudo-random number to create.
return System.Int32

Next() public method

Returns the next pseudo-random Int32 at least minValue and up to maxValue.
/// If >= . ///
public Next ( Int32 minValue, Int32 maxValue ) : Int32
minValue System.Int32 The minimum value of the pseudo-random number to create.
maxValue System.Int32 The maximum value of the pseudo-random number to create.
return System.Int32

NextBytes() public method

Fills a buffer with pseudo-random bytes.
/// If == . ///
public NextBytes ( Byte buffer ) : void
buffer Byte The buffer to fill.
return void

NextDouble() public method

Returns the next pseudo-random Double value.

There are two common ways to create a double floating point using MT19937: using GenerateUInt32 and dividing by 0xFFFFFFFF + 1, or else generating two double words and shifting the first by 26 bits and adding the second.

In a newer measurement of the randomness of MT19937 published in the journal "Monte Carlo Methods and Applications, Vol. 12, No. 5-6, pp. 385 – 393 (2006)" entitled "A Repetition Test for Pseudo-Random Number Generators", it was found that the 32-bit version of generating a double fails at the 95% confidence level when measuring for expected repetitions of a particular number in a sequence of numbers generated by the algorithm.

Due to this, the 53-bit method is implemented here and the 32-bit method of generating a double is not. If, for some reason, the 32-bit method is needed, it can be generated by the following: (Double)NextUInt32() / ((UInt64)UInt32.MaxValue + 1);

public NextDouble ( ) : Double
return Double

NextDouble() public method

Returns a pseudo-random number greater than or equal to zero, and either strictly less than one, or less than or equal to one, depending on the value of the given parameter.
public NextDouble ( System.Boolean includeOne ) : Double
includeOne System.Boolean /// If , the pseudo-random number returned will be /// less than or equal to one; otherwise, the pseudo-random number returned will /// be strictly less than one. ///
return Double

NextDoublePositive() public method

Returns a pseudo-random number greater than 0.0 and less than 1.0.
public NextDoublePositive ( ) : Double
return Double

NextSingle() public method

Returns a pseudo-random number between 0.0 and 1.0.
public NextSingle ( ) : System.Single
return System.Single

NextSingle() public method

Returns a pseudo-random number greater than or equal to zero, and either strictly less than one, or less than or equal to one, depending on the value of the given boolean parameter.
public NextSingle ( System.Boolean includeOne ) : System.Single
includeOne System.Boolean /// If , the pseudo-random number returned will be /// less than or equal to one; otherwise, the pseudo-random number returned will /// be strictly less than one. ///
return System.Single

NextSinglePositive() public method

Returns a pseudo-random number greater than 0.0 and less than 1.0.
public NextSinglePositive ( ) : System.Single
return System.Single

NextUInt32() public method

Returns the next pseudo-random UInt32.
public NextUInt32 ( ) : UInt32
return System.UInt32

NextUInt32() public method

Returns the next pseudo-random UInt32 up to maxValue.
public NextUInt32 ( UInt32 maxValue ) : UInt32
maxValue System.UInt32 /// The maximum value of the pseudo-random number to create. ///
return System.UInt32

NextUInt32() public method

Returns the next pseudo-random UInt32 at least minValue and up to maxValue.
/// If >= . ///
public NextUInt32 ( UInt32 minValue, UInt32 maxValue ) : UInt32
minValue System.UInt32 The minimum value of the pseudo-random number to create.
maxValue System.UInt32 The maximum value of the pseudo-random number to create.
return System.UInt32