Mrg32k3a Class

Represents a pseudo-random number generator based on Pierre L'Ecuyer's MRG32k3a combined multiple recursive generator.

Definition

Namespace: Numerics.NET.Random
Assembly: Numerics.NET (in Numerics.NET.dll) Version: 10.5.0
C#
public sealed class Mrg32k3a : RandomSource<ScalarGenerator32<Mrg32k3aEngine>>, 
	IRandomSourceFactory<Mrg32k3a>, IAdvanceable, IJumpable
Inheritance
Object  →  RandomSource<ScalarGenerator32<Mrg32k3aEngine>>  →  Mrg32k3a
Implements
IAdvanceable, IJumpable, IRandomSourceFactory<Mrg32k3a>

Remarks

Use the Mrg32k3a class to represent a pseudo-random number generator that uses Pierre L'Ecuyer's MRG32k3a combined multiple recursive generator. MRG32k3a has a six-word state split across two third-order recurrences modulo 4294967087 and 4294944443, and combines the two recurrence values to produce 32-bit output.

This generator is especially useful for simulation and parallel Monte Carlo work because the original RngStreams design partitions the sequence into long, non-overlapping streams and substreams. The classic hierarchy uses streams spaced 2127 outputs apart and substreams spaced 276 outputs apart. In Mrg32k3a, LongJump() moves to the next classic stream and Jump() moves to the next classic substream.

When Standard is used, StreamAddress is interpreted as the classic RngStreams address [stream, substream]. The first segment is applied as a 2127 stream jump and the second segment is applied as a 276 substream jump. Addresses deeper than two segments are rejected for the standard profile. The default profile uses the general Numerics.NET stream derivation rules unless no stream address is supplied, in which case compatible MRG32k3a state initialization is used.

SimOpt three-level stream addressing is also available through JumpSimOptStream(UInt64), JumpSimOptSubstream(UInt64), and JumpSimOptSubsubstream(UInt64). These methods use jumps of 2141, 294, and 247 outputs respectively, but are explicit operations and are not used by Standard.

The generator supports fixed stream jumps, state persistence, copying, and direct six-word state initialization. It is intended for reproducible simulation work, not for cryptographic use.

Reference: Pierre L'Ecuyer, "Good Parameters and Implementations for Combined Multiple Recursive Random Number Generators," 1999.

Example

C#
var rng = new Mrg32k3a(42);
double value = rng.NextDouble();

// Classic RngStreams addressing: stream 3, substream 5.
var stream = new Mrg32k3a(
    seed: 42,
    streamAddress: new StreamAddress(new ulong[] { 3, 5 }),
    seedProfile: SeedProfile.Standard);

Constructors

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

Properties

BitsPerWord Gets the number of bits per word in the generator's native output.
(Overrides RandomSource<TGenerator>.BitsPerWord)
JumpSize Gets the size category of the primary jump operation.
LongJumpSize Gets the size category of the long jump operation.
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

Advance Advances the RNG state by the specified number of outputs.
Copy Creates an exact copy of this generator with the same state.
Create Creates a new Mrg32k3a instance from the specified options.
CreateStreamPartition Creates a jump-based stream partition for generating spaced MRG32k3a streams.
CreateStreamTree Creates a hierarchical stream tree for generating derived MRG32k3a 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)
Jump Advances the generator to the next substream (classic RngStreams 2^76 jump).
Jumped Returns a copy of this generator advanced by the specified number of substream jumps.
JumpSimOptStream Advances the generator by the specified number of SimOpt stream jumps (2^141 outputs each).
JumpSimOptSubstream Advances the generator by the specified number of SimOpt substream jumps (2^94 outputs each).
JumpSimOptSubsubstream Advances the generator by the specified number of SimOpt subsubstream jumps (2^47 outputs each).
JumpSimOptSubsubstreamed Returns a copy of this generator advanced by the specified number of SimOpt subsubstream jumps.
LoadState Loads the generator's state from the source span in a stable little-endian format.
(Inherited from RandomSource<TGenerator>)
LongJump Advances the generator to the next stream (classic RngStreams 2^127 jump).
LongJumped Returns a copy of this generator advanced by the specified number of stream jumps.
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