Philox 4x 32 Class
Definition
Assembly: Numerics.NET (in Numerics.NET.dll) Version: 10.3.0
public sealed class Philox4x32 : CounterBasedRandomSource<CounterBasedGenerator32<Philox4x32Engine>, uint>,
IRandomSourceFactory<Philox4x32>, IJumpable, IAdvanceable- Inheritance
- Object → RandomSource<CounterBasedGenerator32<Philox4x32Engine>> → CounterBasedRandomSource<CounterBasedGenerator32<Philox4x32Engine>, UInt32> → Philox4x32
- Implements
- IAdvanceable, IJumpable, IRandomSourceFactory<Philox4x32>
Remarks
Use the Philox4x32 class to represent a counter-based pseudo-random number generator that uses the Philox 4x32 algorithm by John K. Salmon et al.
Philox is a counter-based random number generator that produces a bijection from an n-bit input counter to an n-bit random output. This allows for direct computation of the Nth random number without computing all previous numbers.
Key features include excellent statistical quality (passes BigCrush), reproducibility, and the ability to generate arbitrary independent streams by setting different keys.
Counter-based generators are particularly useful for parallel computing where each thread can have its own counter range, ensuring no overlap in sequences.
Performance: Philox4x32 generates random numbers in blocks of 4, making it efficient for bulk generation.
Use cases:
- Parallel computing with independent, non-overlapping sequences
- Reproducible simulations requiring random access to sequences
- Applications requiring deterministic stream partitioning
Reference: John K. Salmon, Mark A. Moraes, Ron O. Dror, and David E. Shaw. "Parallel random numbers: as easy as 1, 2, 3." SC 2011.
Example
var rng = new Philox4x32(42);
rng.SetCounter(new uint[] { 0, 0, 0, 0 });
uint value = rng.NextUInt32();Constructors
| Philox4x32() | Initializes a new instance of the Philox4x32 class using OS entropy. |
| Philox4x32( | Initializes a new instance of the Philox4x32 class with the specified options. |
| Philox4x32( | Initializes a new instance of the Philox4x32 class from saved state. |
| Philox4x32( | Initializes a new instance of the Philox4x32 class with the specified seed. |
| Philox4x32( | Initializes a new instance of the Philox4x32 class with the specified seed array. |
| Philox4x32( | Initializes a new instance of the Philox4x32 class with the specified seed. |
| Philox4x32( | Initializes a new instance of the Philox4x32 class with the specified seed array. |
Properties
| Bits |
Gets the number of bits per word in the generator's native output.
(Overrides RandomSource<TGenerator>.BitsPerWord) |
| Block |
Gets the number of output words per block produced by this generator.
(Inherited from CounterBasedRandomSource<TGenerator, TWord>) |
| Counter |
Gets the number of words in the engine counter.
(Inherited from CounterBasedRandomSource<TGenerator, TWord>) |
| Jump | Gets the size category of the primary jump operation. |
| Key |
Gets the number of words in the engine key.
(Inherited from CounterBasedRandomSource<TGenerator, TWord>) |
| 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. |
| Advance |
Advances the counter by the specified number of blocks.
(Inherited from CounterBasedRandomSource<TGenerator, TWord>) |
| Copy | Returns a deep copy of this RNG. |
| Create | Creates a new Philox4x32 instance from the specified options. |
| Create | Creates a jump-based stream partition for generating independent RNG streams. |
| Create | Creates a hierarchical stream tree for generating independent RNG 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>) |
| From | Creates a new Philox4x32 instance with the specified key and counter initialized to zero. |
| From | Creates a new Philox4x32 instance with the specified key and counter. |
| Generate |
Computes the output block for the current key and counter.
(Inherited from CounterBasedRandomSource<TGenerator, TWord>) |
| Get |
Copies the current counter into the provided destination span.
(Inherited from CounterBasedRandomSource<TGenerator, TWord>) |
| Get | Serves as the default hash function. (Inherited from Object) |
| Get |
Copies the current key into the provided destination span.
(Inherited from CounterBasedRandomSource<TGenerator, TWord>) |
| 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) |
| Jumped | Returns a new instance of the random number generator that is advanced by a specified number of jumps in the sequence. |
| Load |
Loads the generator's state from the source span in a stable little-endian format.
(Inherited from RandomSource<TGenerator>) |
| Long | Returns a new instance of the random number generator that is advanced by a specified number of long jumps in the sequence. |
| 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>) |
| Reset |
Resets the counter to all zeros.
(Inherited from CounterBasedRandomSource<TGenerator, TWord>) |
| Save |
Saves the generator's state to the destination span in a stable little-endian format.
(Inherited from RandomSource<TGenerator>) |
| Set |
Sets the counter to the specified value.
(Inherited from CounterBasedRandomSource<TGenerator, TWord>) |
| Set |
Sets the key to the specified value.
(Inherited from CounterBasedRandomSource<TGenerator, TWord>) |
| ToString | Returns a string that represents the current object. (Inherited from Object) |