MersenneTwister Constructor

Definition

Namespace: Numerics.NET.Random
Assembly: Numerics.NET (in Numerics.NET.dll) Version: 10.3.0

Overload List

MersenneTwister() Constructs a new MersenneTwister class using a time-dependent default seed value.
MersenneTwister(Int32) Initializes a new instance of the MersenneTwister class using the specified integer seed value.
MersenneTwister(Int32[]) Initializes a new instance of the MersenneTwister class using the specified array of integer seeds.
MersenneTwister(RandomOptions) Initializes a new instance of the MersenneTwister class with the specified options.
MersenneTwister(ReadOnlySpan<Byte>) Initializes a new instance of the MersenneTwister class from saved state.
MersenneTwister(Int64, SeedProfile) Constructs a new MersenneTwister class using the specified seed value.
MersenneTwister(ReadOnlySpan<UInt32>, SeedProfile) Constructs a new MersenneTwister class using the specified seed array of seed values.
MersenneTwister(Int64, StreamAddress, SeedProfile) Constructs a new MersenneTwister class using the specified seed value.
MersenneTwister(ReadOnlySpan<UInt32>, StreamAddress, SeedProfile) Constructs a new MersenneTwister class using the specified seed array of seed values.

MersenneTwister

Constructs a new MersenneTwister class using a time-dependent default seed value.
C#
public MersenneTwister()

Remarks

Although the seed value is time-dependent, it may not change fast enough to be different on successive invocations. To ensure two or more random sequences are different, provide different seed values explicitly.

MersenneTwister(Int32)

Initializes a new instance of the MersenneTwister class using the specified integer seed value.
C#
public MersenneTwister(
	int seed
)

Parameters

seed  Int32
The seed value used to initialize the random number generator. Using the same seed produces the same sequence of random numbers.

Remarks

This constructor is provided for compatibility with code that uses integer seeds. For best results, use a sufficiently random seed value. The generator is deterministic for a given seed.

MersenneTwister(Int32[])

Initializes a new instance of the MersenneTwister class using the specified array of integer seeds.
C#
public MersenneTwister(
	int[] seeds
)

Parameters

seeds  Int32[]
An array of 32-bit signed integers to use as the initial seed values for the random number generator.

Remarks

This constructor is obsolete and will be removed in a future release. Use the constructor that accepts an array of unsigned integers instead. The provided seed values are converted to unsigned integers before being used to initialize the generator.

MersenneTwister(RandomOptions)

Initializes a new instance of the MersenneTwister class with the specified options.
C#
public MersenneTwister(
	RandomOptions options
)

Parameters

options  RandomOptions
The initialization options containing seed, stream ID, and seed profile.

MersenneTwister(ReadOnlySpan<Byte>)

Initializes a new instance of the MersenneTwister class from saved state.
C#
public MersenneTwister(
	ReadOnlySpan<byte> state
)

Parameters

state  ReadOnlySpan<Byte>
The saved state to restore.

Exceptions

ArgumentExceptionThe length of state is less than the required state size.

MersenneTwister(Int64, SeedProfile)

Constructs a new MersenneTwister class using the specified seed value.
C#
public MersenneTwister(
	long seed,
	SeedProfile seedProfile = SeedProfile.Default
)

Parameters

seed  Int64
A number used to calculate a starting value for the pseudo-random number sequence.
seedProfile  SeedProfile  (Optional)
 

Remarks

Different seeds produce different random sequences. You can produce the same sequence repeatedly by providing the same seed value each time.

MersenneTwister(ReadOnlySpan<UInt32>, SeedProfile)

Constructs a new MersenneTwister class using the specified seed array of seed values.
C#
public MersenneTwister(
	ReadOnlySpan<uint> seedMaterial,
	SeedProfile seedProfile = SeedProfile.Default
)

Parameters

seedMaterial  ReadOnlySpan<UInt32>
An array of integers used to calculate a starting value for the pseudo-random number sequence.
seedProfile  SeedProfile  (Optional)
 

Remarks

The maximum length of seedMaterial is 16383. All elements after the 16383rd element are ignored.

Different seeds produce different random sequences. You can produce the same sequence repeatedly by providing the same seed value each time.

Exceptions

ArgumentNullExceptionseedMaterial is null.

MersenneTwister(Int64, StreamAddress, SeedProfile)

Constructs a new MersenneTwister class using the specified seed value.
C#
public MersenneTwister(
	long seed,
	StreamAddress streamAddress,
	SeedProfile seedProfile = SeedProfile.Default
)

Parameters

seed  Int64
A number used to calculate a starting value for the pseudo-random number sequence.
streamAddress  StreamAddress
Optional stream identifier for stream selection.
seedProfile  SeedProfile  (Optional)
The seed profile to use for initialization.

MersenneTwister(ReadOnlySpan<UInt32>, StreamAddress, SeedProfile)

Constructs a new MersenneTwister class using the specified seed array of seed values.
C#
public MersenneTwister(
	ReadOnlySpan<uint> seedMaterial,
	StreamAddress streamAddress,
	SeedProfile seedProfile = SeedProfile.Default
)

Parameters

seedMaterial  ReadOnlySpan<UInt32>
An array of integers used to calculate a starting value for the pseudo-random number sequence.
streamAddress  StreamAddress
Optional stream identifier for stream selection.
seedProfile  SeedProfile  (Optional)
The seed profile to use for initialization.

Exceptions

ArgumentNullExceptionseedMaterial is null.

See Also