CX Framework
Cross-platform C utility framework
Loading...
Searching...
No Matches
State Manipulation

Functions

void pcgAdvance (PcgState *rng, uint64 delta)
 

Detailed Description

Advanced functions for manipulating generator state.

Function Documentation

◆ pcgAdvance()

void pcgAdvance ( PcgState rng,
uint64  delta 
)

Advances the RNG state forward (or backward) by a specified number of steps

Efficiently jumps the RNG state forward or backward without generating intermediate values. This is useful for:

  • Skipping ahead in a sequence for parallel generation
  • Implementing "save states" in simulations
  • Jumping to specific points in a reproducible sequence

The algorithm uses O(log(delta)) time complexity based on fast exponentiation, making even very large jumps efficient.

Note: Passing a negative value (as uint64) will advance backward, effectively "jumping back" in the sequence.

Example:

PcgState rng1, rng2;
pcgSeed(&rng1, 42, 54);
pcgSeed(&rng2, 42, 54);
pcgAdvance(&rng2, 1000); // Jump ahead 1000 steps
// rng1 and rng2 are now at different points in the same sequence
// Generate 1000 values from rng1 would bring it to rng2's state
void pcgAdvance(PcgState *rng, uint64 delta)
void pcgSeed(PcgState *rng, uint64 initstate, uint64 initseq)
Definition pcg.h:54
Parameters
rngPointer to initialized PCG state
deltaNumber of steps to advance (can be negative to go backward)