Mrg 32k 3a Class
Definition
Assembly: Numerics.NET (in Numerics.NET.dll) Version: 10.5.0
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
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( | Initializes a new instance of the Mrg32k3a class with the specified options. |
| Mrg32k3a( | Initializes a new instance of the Mrg32k3a class from saved state. |
| Mrg32k3a( | Initializes a new instance of the Mrg32k3a class with the specified seed. |
| Mrg32k3a( | Initializes a new instance of the Mrg32k3a class with the specified seed array. |
| Mrg32k3a( | Initializes a new instance of the Mrg32k3a class with the specified seed. |
| Mrg32k3a( | Initializes a new instance of the Mrg32k3a class with the specified seed array. |
| Mrg32k3a( | Initializes a new instance of the Mrg32k3a class from direct MRG32k3a state words. |
Properties
| Bits |
Gets the number of bits per word in the generator's native output.
(Overrides RandomSource<TGenerator>.BitsPerWord) |
| Jump | Gets the size category of the primary jump operation. |
| Long | Gets the size category of the long jump operation. |
| Name |
Gets a human-readable name for this random number generator.
(Overrides RandomSource<TGenerator>.Name) |
| State |
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. |
| Create | Creates a jump-based stream partition for generating spaced MRG32k3a streams. |
| Create | Creates a hierarchical stream tree for generating derived MRG32k3a streams. |
| Equals | Determines whether the specified object is equal to the current object. (Inherited from Object) |
| Fill( |
Fills a span with random 32-bit unsigned integer values.
(Inherited from RandomSource<TGenerator>) |
| Fill( |
Fills a span with random 32-bit signed integers less than the specified maximum.
(Inherited from RandomSource<TGenerator>) |
| Fill( |
Fills a span with random 64-bit signed integers less than the specified maximum.
(Inherited from RandomSource<TGenerator>) |
| Fill( |
Fills a span with random 32-bit signed integers within a specified range.
(Inherited from RandomSource<TGenerator>) |
| Fill( |
Fills a span with random 64-bit signed integers within a specified range.
(Inherited from RandomSource<TGenerator>) |
| Get | Serves as the default hash function. (Inherited from Object) |
| Get |
Returns the current state of the generator as a byte array.
(Inherited from RandomSource<TGenerator>) |
| Get | Gets 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. |
| Jump | Advances the generator by the specified number of SimOpt stream jumps (2^141 outputs each). |
| Jump | Advances the generator by the specified number of SimOpt substream jumps (2^94 outputs each). |
| Jump | Advances the generator by the specified number of SimOpt subsubstream jumps (2^47 outputs each). |
| Jump | Returns a copy of this generator advanced by the specified number of SimOpt subsubstream jumps. |
| Load |
Loads the generator's state from the source span in a stable little-endian format.
(Inherited from RandomSource<TGenerator>) |
| Long | Advances the generator to the next stream (classic RngStreams 2^127 jump). |
| Long | 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( |
Returns a non-negative random integer less than the specified maximum.
(Inherited from RandomSource<TGenerator>) |
| Next( |
Returns a random integer within a specified range.
(Inherited from RandomSource<TGenerator>) |
| Next |
Fills the elements of a specified array of bytes with random numbers.
(Inherited from RandomSource<TGenerator>) |
| Next |
Fills the elements of a specified span of bytes with random numbers.
(Inherited from RandomSource<TGenerator>) |
| Next |
Fills the elements of a specified span of bytes with random numbers.
(Inherited from RandomSource<TGenerator>) |
| Next |
Fills the elements of a specified span of bytes with random numbers.
(Inherited from RandomSource<TGenerator>) |
| Next |
Returns a random floating-point number in the range [0.0, 1.0).
(Inherited from RandomSource<TGenerator>) |
| Next |
Returns a non-negative random 64-bit integer.
(Inherited from RandomSource<TGenerator>) |
| Next |
Returns a non-negative random 64-bit integer less than the specified maximum.
(Inherited from RandomSource<TGenerator>) |
| Next |
Returns a random 64-bit integer within a specified range.
(Inherited from RandomSource<TGenerator>) |
| Next |
Returns a random single-precision floating-point number in the range [0.0, 1.0).
(Inherited from RandomSource<TGenerator>) |
| Next |
Returns a random 32-bit unsigned integer.
(Inherited from RandomSource<TGenerator>) |
| Next |
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>) |
| Save |
Saves the generator's state to the destination span in a stable little-endian format.
(Inherited from RandomSource<TGenerator>) |
| ToString | Returns a string that represents the current object. (Inherited from Object) |