C# Класс OpenTK.MersenneTwister

Generates pseudo-random numbers using the Mersenne Twister algorithm.
Наследование: System.Random
Показать файл Открыть проект

Открытые методы

Метод Описание
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.

Защищенные методы

Метод Описание
GenerateUInt32 ( ) : UInt32

Generates a new pseudo-random UInt32.

Приватные методы

Метод Описание
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

Описание методов

GenerateUInt32() защищенный Метод

Generates a new pseudo-random UInt32.
protected GenerateUInt32 ( ) : UInt32
Результат System.UInt32

MersenneTwister() публичный Метод

Creates a new pseudo-random number generator with a default seed.
new System.Random().Random.Next() is used for the seed.
public MersenneTwister ( ) : System
Результат System

MersenneTwister() публичный Метод

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.
Результат System

Next() публичный Метод

Returns the next pseudo-random Int32.
public Next ( ) : Int32
Результат System.Int32

Next() публичный Метод

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.
Результат System.Int32

Next() публичный Метод

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.
Результат System.Int32

NextBytes() публичный Метод

Fills a buffer with pseudo-random bytes.
/// If == . ///
public NextBytes ( Byte buffer ) : void
buffer Byte The buffer to fill.
Результат void

NextDouble() публичный Метод

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
Результат Double

NextDouble() публичный Метод

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. ///
Результат Double

NextDoublePositive() публичный Метод

Returns a pseudo-random number greater than 0.0 and less than 1.0.
public NextDoublePositive ( ) : Double
Результат Double

NextSingle() публичный Метод

Returns a pseudo-random number between 0.0 and 1.0.
public NextSingle ( ) : System.Single
Результат System.Single

NextSingle() публичный Метод

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. ///
Результат System.Single

NextSinglePositive() публичный Метод

Returns a pseudo-random number greater than 0.0 and less than 1.0.
public NextSinglePositive ( ) : System.Single
Результат System.Single

NextUInt32() публичный Метод

Returns the next pseudo-random UInt32.
public NextUInt32 ( ) : UInt32
Результат System.UInt32

NextUInt32() публичный Метод

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. ///
Результат System.UInt32

NextUInt32() публичный Метод

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.
Результат System.UInt32