Skip to content
CryoCryo home
Stdlibrandom

rng

import std::random::rng; · source

Rng

type struct Rng {
    s0: u64;
    s1: u64;
    s2: u64;
    s3: u64;

    static from_seed(seed: u64) -> Rng;
    static from_os() -> Rng;
}

from_seed(seed) gives the same stream for the same seed, which is what you want for tests and simulations; the 64-bit seed is expanded to the 256-bit state with SplitMix64. from_os() seeds unpredictably, falling back to a monotonic-clock and pid mix if the kernel source is briefly unavailable, so it never hard-fails — fine for non-cryptographic use.

Rng is POD, so copying it forks the stream rather than sharing it.

Trait implementations

implement trait RandomSource for struct Rng