fn

manual_seed

None
manual_seed(seed: _int)
source

Set the seed of the default Philox counter-based random number generator.

The Lucid RNG uses a Philox-4×32 counter-based PRNG (Salmon et al., 2011). Unlike stateful RNGs (e.g. Mersenne Twister), Philox is a keyed bijection: given a 64-bit key kk (the seed) and a 64-bit counter cc, it produces a deterministic 128-bit output block via 10 rounds of the Philox permutation:

(r0,r1,r2,r3)=Philox4×32(k,c)(r_0, r_1, r_2, r_3) = \text{Philox}_{4 \times 32}(k,\, c)

Setting the seed to a fixed value k0k_0 fully determines the entire subsequent sampling stream, enabling reproducible experiments.

Parameters

seedint
Non-negative 64-bit integer seed. The same seed always produces the same sequence of random values on the same hardware.

Notes

Calling manual_seed resets the counter to 00 in addition to updating the key kk. Two calls with the same seed produce identical streams regardless of how many samples were drawn in between.

For multi-process reproducibility, seed each worker with a distinct derived seed, e.g. manual_seed(base_seed + worker_id), to avoid correlated streams across processes.

Examples

>>> import lucid
>>> lucid.manual_seed(42)
>>> a = lucid.rand(3)
>>> lucid.manual_seed(42)
>>> b = lucid.rand(3)
>>> (a - b).abs().max().item()
0.0