Nx_core.RngSourceRNG key utilities.
Splittable RNG keys and implicit key management.
Keys are deterministic integers that can be split to derive independent subkeys. run and with_key install an effect handler that provides implicit key threading via next_key; outside any handler a domain-local auto-seeded generator is used as a convenient fallback.
The type for RNG keys.
split ?n k deterministically derives n subkeys from k.
n defaults to 2.
next_key () returns a fresh subkey from the current RNG scope.
Inside a run or with_key block, each call returns a deterministically derived key. Outside any scope, falls back to a domain-local auto-seeded generator (convenient but non-reproducible).
Two calls to next_key () always return different keys.
run ~seed f executes f in an RNG scope seeded by seed.
Every next_key call within f returns a deterministically derived key. The same seed and the same sequence of next_key calls produce the same keys. Scopes nest: an inner run replaces the outer scope for its duration.