MersenneTwister64 Class

Represents a pseudo-random number generator based on the MT19937-64 algorithm.

Definition

Namespace: Numerics.NET.Random
Assembly: Numerics.NET (in Numerics.NET.dll) Version: 10.3.0
C#
public sealed class MersenneTwister64 : RandomSource<BlockGenerator64<MersenneTwister64Engine>>, 
	IRandomSourceFactory<MersenneTwister64>
Inheritance
Object  →  RandomSource<BlockGenerator64<MersenneTwister64Engine>>  →  MersenneTwister64
Implements
IRandomSourceFactory<MersenneTwister64>

Remarks

Use the MersenneTwister64 class to represent a pseudo-random number generator that uses the 64-bit Mersenne Twister algorithm (MT19937-64) by Takuji Nishimura and Makoto Matsumoto.

This generator has a very long period of 219937 - 1 and excellent equidistribution properties. It is widely used in scientific computing and simulations.

The 64-bit version produces different output than the 32-bit MersenneTwister and is optimized for generating 64-bit random numbers.

While MT19937-64 has excellent statistical properties, modern alternatives like Xoshiro256StarStar are typically faster with similar quality.

Seed Profile support:

  • Standard (default): Hiroshima University 2004 reference seeding
  • CPlusPlus: C++11 std::mt19937_64 compatible seeding

Seed profiles affect only the seeding behavior. The generation algorithm remains MT19937-64.

Reference: Takuji Nishimura and Makoto Matsumoto. "Mersenne Twister: A 623-dimensionally equidistributed uniform pseudo-random number generator." ACM Trans. Model. Comput. Simul. 1998.

Example

C#
var rng = new MersenneTwister64(5489);
ulong value = rng.NextUInt64();
double x = rng.NextDouble();

Constructors

MersenneTwister64() Initializes a new instance of the MersenneTwister64 class using OS entropy.
MersenneTwister64(RandomOptions) Initializes a new instance of the MersenneTwister64 class with the specified options.
MersenneTwister64(ReadOnlySpan<Byte>) Initializes a new instance of the MersenneTwister64 class from saved state.
MersenneTwister64(Int64, SeedProfile) Initializes a new instance of the MersenneTwister64 class with the specified seed.
MersenneTwister64(ReadOnlySpan<UInt64>, SeedProfile) Initializes a new instance of the MersenneTwister64 class with the specified seed array.
MersenneTwister64(Int64, StreamAddress, SeedProfile) Initializes a new instance of the MersenneTwister64 class with the specified seed.
MersenneTwister64(ReadOnlySpan<UInt64>, StreamAddress, SeedProfile) Initializes a new instance of the MersenneTwister64 class with the specified seed array.

Properties

BitsPerWord Gets the number of bits per word in the generator's native output.
(Overrides RandomSource<TGenerator>.BitsPerWord)
Name Gets a human-readable name for this random number generator.
(Overrides RandomSource<TGenerator>.Name)
StateSize Gets the number of bytes required to save/load this generator's state.
(Inherited from RandomSource<TGenerator>)
Uncached Gets an uncached facade for this random number generator.
(Inherited from RandomSource<TGenerator>)

Methods

Copy Returns a deep copy of this RNG.
Create Creates a new MersenneTwister64 instance from the specified options.
CreateStreamTree Creates a hierarchical stream tree for generating independent RNG streams.
EqualsDetermines whether the specified object is equal to the current object.
(Inherited from Object)
Fill(Span<UInt32>) Fills a span with random 32-bit unsigned integer values.
(Inherited from RandomSource<TGenerator>)
Fill(Span<Int32>, Int32) Fills a span with random 32-bit signed integers less than the specified maximum.
(Inherited from RandomSource<TGenerator>)
Fill(Span<Int64>, Int64) Fills a span with random 64-bit signed integers less than the specified maximum.
(Inherited from RandomSource<TGenerator>)
Fill(Span<Int32>, Int32, Int32) Fills a span with random 32-bit signed integers within a specified range.
(Inherited from RandomSource<TGenerator>)
Fill(Span<Int64>, Int64, Int64) Fills a span with random 64-bit signed integers within a specified range.
(Inherited from RandomSource<TGenerator>)
GetHashCodeServes as the default hash function.
(Inherited from Object)
GetState Returns the current state of the generator as a byte array.
(Inherited from RandomSource<TGenerator>)
GetTypeGets the Type of the current instance.
(Inherited from Object)
LoadState Loads the generator's state from the source span in a stable little-endian format.
(Inherited from RandomSource<TGenerator>)
Next() Returns a non-negative random integer.
(Inherited from RandomSource<TGenerator>)
Next(Int32) Returns a non-negative random integer less than the specified maximum.
(Inherited from RandomSource<TGenerator>)
Next(Int32, Int32) Returns a random integer within a specified range.
(Inherited from RandomSource<TGenerator>)
NextBytes(Byte[]) Fills the elements of a specified array of bytes with random numbers.
(Inherited from RandomSource<TGenerator>)
NextBytes(Span<Byte>) Fills the elements of a specified span of bytes with random numbers.
(Inherited from RandomSource<TGenerator>)
NextBytes(Byte[], Boolean) Fills the elements of a specified span of bytes with random numbers.
(Inherited from RandomSource<TGenerator>)
NextBytes(Span<Byte>, Boolean) Fills the elements of a specified span of bytes with random numbers.
(Inherited from RandomSource<TGenerator>)
NextDouble Returns a random floating-point number in the range [0.0, 1.0).
(Inherited from RandomSource<TGenerator>)
NextInt64() Returns a non-negative random 64-bit integer.
(Inherited from RandomSource<TGenerator>)
NextInt64(Int64) Returns a non-negative random 64-bit integer less than the specified maximum.
(Inherited from RandomSource<TGenerator>)
NextInt64(Int64, Int64) Returns a random 64-bit integer within a specified range.
(Inherited from RandomSource<TGenerator>)
NextSingle Returns a random single-precision floating-point number in the range [0.0, 1.0).
(Inherited from RandomSource<TGenerator>)
NextUInt32 Returns a random 32-bit unsigned integer.
(Inherited from RandomSource<TGenerator>)
NextUInt64 Returns a random 64-bit unsigned integer.
(Inherited from RandomSource<TGenerator>)
Reinitialize Reinitializes this random number generator using the specified initialization options.
(Inherited from RandomSource<TGenerator>)
SaveState Saves the generator's state to the destination span in a stable little-endian format.
(Inherited from RandomSource<TGenerator>)
ToStringReturns a string that represents the current object.
(Inherited from Object)

See Also