IAdvanceable Interface

Represents an RNG that can be moved forward by a specific delta in O(log delta) time.

Definition

Namespace: Numerics.NET.Random
Assembly: Numerics.NET (in Numerics.NET.dll) Version: 10.3.0
C#
public interface IAdvanceable

Remarks

An advanceable RNG supports deterministically advancing its state by a specified number of outputs without actually generating those intermediate values. This is useful for:

  • Skipping ahead in a sequence without computational overhead
  • Creating independent subsequences with guaranteed non-overlap
  • Parallel computation with deterministic partitioning

Semantics:

Advance(delta) is equivalent to calling NextUInt64() exactly delta times, but is computed in O(log delta) time using the mathematical properties of the generator's state transition function.

Modular Arithmetic:

Advancement uses wrap-around modular arithmetic consistent with the generator's state space and period. Advancing past the end of the cycle wraps as expected for that generator.

Unit of Advancement:

The unit is 64-bit core outputs (NextUInt64()), not distribution samples or other derived random values.

  Important

Not all RNGs support advancement. Counter-based RNGs (e.g., Philox, Threefry, ChaCha) and some LCG-based RNGs (e.g., PCG) implement this interface. Linear feedback shift register RNGs (e.g., Xoshiro, Xoroshiro) typically do not, but may implement IJumpable instead.

Example

C#
// Create two RNGs with the same seed
var rng1 = new Pcg64(42);
var rng2 = new Pcg64(42);

// Advance rng2 by 1000 steps
((IAdvanceable)rng2).Advance(1000);

// Now generate 1000 values from rng1
for (int i = 0; i < 1000; i++)
{
    rng1.NextUInt64();
}

// Both RNGs should now produce the same value
Assert.That(rng1.NextUInt64(), Is.EqualTo(rng2.NextUInt64()));

Methods

Advance Advances the RNG state by the specified number of outputs.

See Also