Class MT19937Generator
Represents a Mersenne Twister pseudo-random number generator with period 2^19937-1.
Inherited Members
Namespace: Experior.Core.Mathematics.Statistics.Generators.Pseudo
Assembly: Experior.Core.dll
Syntax
public class MT19937Generator : Generator
Remarks
The MT19937Generator type bases upon information and the implementation presented on the Mersenne Twister Home Page.
Constructors
MT19937Generator()
Initializes a new instance of the MT19937Generator class, using a time-dependent default seed value.
Declaration
public MT19937Generator()
MT19937Generator(Int32)
Initializes a new instance of the MT19937Generator class, using the specified seed value.
Declaration
public MT19937Generator(int seed)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | seed | 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. |
MT19937Generator(Int32[])
Initializes a new instance of the MT19937Generator class, using the specified seed array.
Declaration
public MT19937Generator(int[] seedArray)
Parameters
Type | Name | Description |
---|---|---|
System.Int32[] | seedArray | An array of numbers used to calculate a starting values for the pseudo-random number sequence. If negative numbers are specified, the absolute values of them are used. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
MT19937Generator(UInt32)
Initializes a new instance of the MT19937Generator class, using the specified seed value.
Declaration
public MT19937Generator(uint seed)
Parameters
Type | Name | Description |
---|---|---|
System.UInt32 | seed | An unsigned number used to calculate a starting value for the pseudo-random number sequence. |
MT19937Generator(UInt32[])
Initializes a new instance of the MT19937Generator class, using the specified seed array.
Declaration
public MT19937Generator(uint[] seedArray)
Parameters
Type | Name | Description |
---|---|---|
System.UInt32[] | seedArray | An array of unsigned numbers used to calculate a starting values for the pseudo-random number sequence. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
Properties
CanReset
Gets a value indicating whether the MT19937Generator can be reset, so that it produces the same pseudo-random number sequence again.
Declaration
public override bool CanReset { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
|
Overrides
Methods
Next()
Returns a nonnegative random number less than System.Int32.MaxValue.
Declaration
public override int Next()
Returns
Type | Description |
---|---|
System.Int32 | A 32-bit signed integer greater than or equal to 0, and less than System.Int32.MaxValue; that is,
the range of return values includes 0 but not |
Overrides
Next(Int32)
Returns a nonnegative random number less than the specified maximum.
Declaration
public override int Next(int maxValue)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | maxValue | The exclusive upper bound of the random number to be generated.
|
Returns
Type | Description |
---|---|
System.Int32 | A 32-bit signed integer greater than or equal to 0, and less than |
Overrides
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException |
Next(Int32, Int32)
Returns a random number within the specified range.
Declaration
public override int Next(int minValue, int maxValue)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | minValue | The inclusive lower bound of the random number to be generated. |
System.Int32 | maxValue | The exclusive upper bound of the random number to be generated.
|
Returns
Type | Description |
---|---|
System.Int32 | A 32-bit signed integer greater than or equal to |
Overrides
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException |
NextBoolean()
Returns a random Boolean value.
Declaration
public override bool NextBoolean()
Returns
Type | Description |
---|---|
System.Boolean | A System.Boolean value. |
Overrides
Remarks
Buffers 31 random bits for future calls, so the random number generator is only invoked once in every 31 calls.
NextBytes(Byte[])
Fills the elements of a specified array of bytes with random numbers.
Declaration
public override void NextBytes(byte[] buffer)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | buffer | An array of bytes to contain random numbers. |
Overrides
Remarks
Each element of the array of bytes is set to a random number greater than or equal to 0, and less than or equal to System.Byte.MaxValue.
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
NextDouble()
Returns a nonnegative floating point random number less than 1.0.
Declaration
public override double NextDouble()
Returns
Type | Description |
---|---|
System.Double | A double-precision floating point number greater than or equal to 0.0, and less than 1.0; that is, the range of return values includes 0.0 but not 1.0. |
Overrides
NextDouble(Double)
Returns a nonnegative floating point random number less than the specified maximum.
Declaration
public override double NextDouble(double maxValue)
Parameters
Type | Name | Description |
---|---|---|
System.Double | maxValue | The exclusive upper bound of the random number to be generated.
|
Returns
Type | Description |
---|---|
System.Double | A double-precision floating point number greater than or equal to 0.0, and less than |
Overrides
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException |
NextDouble(Double, Double)
Returns a floating point random number within the specified range.
Declaration
public override double NextDouble(double minValue, double maxValue)
Parameters
Type | Name | Description |
---|---|---|
System.Double | minValue | The inclusive lower bound of the random number to be generated.
The range between |
System.Double | maxValue | The exclusive upper bound of the random number to be generated.
|
Returns
Type | Description |
---|---|
System.Double | A double-precision floating point number greater than or equal to |
Overrides
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException | |
System.ArgumentException |
NextInclusiveMaxValue()
Returns a nonnegative random number less than or equal to System.Int32.MaxValue.
Declaration
public int NextInclusiveMaxValue()
Returns
Type | Description |
---|---|
System.Int32 | A 32-bit signed integer greater than or equal to 0, and less than or equal to System.Int32.MaxValue;
that is, the range of return values includes 0 and |
NextUInt()
Returns an unsigned random number.
Declaration
public uint NextUInt()
Returns
Type | Description |
---|---|
System.UInt32 | A 32-bit unsigned integer greater than or equal to System.UInt32.MinValue and
less than or equal to |
Reset()
Resets the MT19937Generator, so that it produces the same pseudo-random number sequence again.
Declaration
public override bool Reset()
Returns
Type | Description |
---|---|
System.Boolean | true. |