Skip to main content

Module pcg

Module pcg 

Source
Expand description

PCG-RXS-M-XS 64/64 random number generator nodes.

These nodes implement the PCG (Permuted Congruential Generator) family algorithm with the RXS-M-XS output permutation. The key property is O(log N) seek: any position in the sequence can be computed directly without iterating from the beginning. This makes it ideal for deterministic parallel workloads where each thread jumps to its own region of the sequence.

Three nodes are provided:

  • Pcg — fixed seed and stream, position is the wire input
  • PcgStream — fixed seed, both position and stream are wire inputs
  • CycleWalk — bijective permutation of [0, range) via cycle-walking

CycleWalk uses multi-source #[poly_const] to derive a CycleWalkState from (range, seed, stream) at construction time, plus compiled_u64 = ... / jit_constants = ... overrides that capture the cached Feistel state by Copy and publish [range, seed, inc] to the JIT classifier.

Structs§

CycleWalk
Bijective permutation of [0, range) via cycle-walking over PCG.
CycleWalkState
Pre-computed Feistel state for the cycle_walk node. Built once at construction from (range, seed, stream) via the multi-source #[poly_const] setup; consumed read-only by every cycle and by the compiled_u64 override’s captured closure.
Pcg
PCG-RXS-M-XS 64/64 random number generator with fixed seed and stream.
PcgStream
PCG-RXS-M-XS 64/64 with runtime stream selection.

Constants§

FEISTEL_ROUNDS
Number of Feistel rounds. 6 rounds provides good diffusion.
MULT
LCG multiplier for the 64-bit state. The LCG multiplier of the 64-bit state.

Functions§

build_cycle_walk_state
Joint Feistel-state derivation. Single-call construction-time invocation per node instance; the macro emits the call inside the generated CycleWalk::new(range, seed, stream).
cycle_walk_inner
Apply cycle-walking with the Feistel bijection.
pcg_output
Apply the RXS-M-XS output permutation to an LCG state.
pcg_seek
Seek to an arbitrary position in the PCG sequence in O(log N) time.