Skip to main content

Module rng

Module rng 

Source
Expand description

Deterministic per-particle random streams and a parallel driver.

Every particle history draws from its own stream, keyed on (run seed, particle index). The generator is ChaCha8 (the rand_chacha crate, MIT OR Apache-2.0): a counter-based design in which the stream identifier is part of the cipher state, so streams for different indices are distinct keystreams by construction, not segments of one sequence spaced apart. Counter-based generators for parallel Monte Carlo are described in J. K. Salmon, M. A. Moraes, R. O. Dror, D. E. Shaw, “Parallel random numbers: as easy as 1, 2, 3”, Proc. SC’11 (2011); ChaCha is D. J. Bernstein, “ChaCha, a variant of Salsa20” (2008), here with 8 rounds.

The parallel driver run_particles fixes the floating-point summation order independent of the thread count: particles are split into chunks of a caller-chosen, thread-independent size, each chunk gets its own tally, and the chunk tallies are merged in chunk-index order. The determinism test is lindhard/tests/determinism.rs. Chunks are evaluated in consecutive batches of a few chunks per worker and each batch is merged before the next starts, so the number of partial tallies held at once is bounded by the pool size, not by the history count; batching never changes a chunk, a stream or the merge order.

Functions§

run_particles
Run n_particles histories in parallel and return the merged tally.
run_particles_range
run_particles for the global particle indices first_index..first_index + n_particles: particle first_index + k uses the stream stream(seed, first_index + k) and is passed that index.
stream
Random stream for particle index of the run with the given seed.
uniform
Uniform draw on [0, 1) with 53 random bits: the top 53 bits of one next_u64(), scaled by the exact power of two 2^-53.

Type Aliases§

ParticleRng
The generator type returned by stream.