Philox4x64Engine Structure

Represents a Philox 4x64-10 counter-based random number generator engine with 64-bit output.

Definition

Namespace: Numerics.NET.Random.Engines
Assembly: Numerics.NET (in Numerics.NET.dll) Version: 10.3.0
C#
public struct Philox4x64Engine : IBlockEngine<ulong>, 
	IRandomEngine, IStateful, ICounterBased<ulong>, IJumpable, 
	IAdvanceable
Inheritance
Object  →  ValueType  →  Philox4x64Engine
Implements
IBlockEngine<UInt64>, ICounterBased<UInt64>, IRandomEngine, IAdvanceable, IJumpable, IStateful

Remarks

The Philox 4x64-10 engine is a counter-based (CBRNG) random number generator that uses a bijective function to transform a 256-bit counter into 256-bit random output (4 × 64-bit words). It uses 10 rounds of the Philox bijection for excellent statistical quality.

Algorithm Details:

  • Key size: 128 bits (2 × 64-bit words)
  • Counter size: 256 bits (4 × 64-bit words)
  • Block size: 256 bits (4 × 64-bit words)
  • Rounds: 10
  • Statistical quality: Passes BigCrush

Counter-Based Design:

As a counter-based generator, Philox allows:

  • Direct position access: Jump to any position in O(1) by setting the counter
  • Parallel generation: Multiple threads can use different counter ranges
  • Reproducibility: Same key/counter always produces the same output block

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

C#
var engine = new Philox4x64Engine();
engine.Seed(SeedSequences.SplitMix64(42));

ulong value = engine.Next();

// Set counter for direct position access
ulong[] counter = new ulong[4] { 0, 0, 0, 0 };
engine.SetCounter(counter);

// Jump ahead by 1000 blocks
engine.AdvanceBlock(1000);

Constructors

Philox4x64Engine Initializes a new Philox4x64 engine.

Properties

BitsPerWord Gets the native word size in bits.
BlockLength Gets the number of native words addressable in each block.
CounterLength Gets the number of words in the engine counter.
JumpSize Gets the size category of the primary jump operation.
KeyLength Gets the number of words in the engine key.
LongJumpSize Gets the size category of the long jump operation.
Name Gets a human-readable name for this engine.
StateSize Gets the number of bytes required to save/load this engine's state.

Methods

Advance Advances the RNG state by the specified number of outputs.
AdvanceBlock() Advances the engine state to the next block (next entropy window).
AdvanceBlock(UInt64) Advances the counter by the specified number of blocks.
EqualsIndicates whether this instance and a specified object are equal.
(Inherited from ValueType)
Fill Fills the destination span with values from a contiguous range of indices within the current block.
GenerateBlock() Computes the output block for the current key and counter.
GenerateBlock(ReadOnlySpan<UInt64>, ReadOnlySpan<UInt64>, Span<UInt64>) Generates a block of random output by applying the Philox bijection.
GetCounter Copies the current counter into the provided destination span.
GetHashCodeReturns the hash code for this instance.
(Inherited from ValueType)
GetKey Copies the current key into the provided destination span.
GetTypeGets the Type of the current instance.
(Inherited from Object)
Jump Jumps the RNG forward by the specified number of primary jump strides.
LoadState Loads the engine's state from the source span in a stable little-endian format.
LongJump Jumps the RNG forward by the specified number of long jump strides.
Output Returns the native word at the specified index within the current block.
ResetCounter Resets the counter to all zeros.
SaveState Saves the engine's state to the destination span in a stable little-endian format.
Seed(ReadOnlySpan<UInt64>) Directly sets the Philox key with counter initialized to zero.
Seed(SeedSequence) Initializes the engine state from a seed sequence.
Seed(ReadOnlySpan<UInt64>, ReadOnlySpan<UInt64>) Directly sets the Philox key and counter.
SetCounter Sets the counter to the specified value.
SetKey Sets the key to the specified value.
ToStringReturns the fully qualified type name of this instance.
(Inherited from ValueType)

See Also