Skip to content
CryoCryo home
Stdlibrandom

rng

import std::random::rng; · source

Types

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.

Properties

PropertyType
s0u64
s1u64
s2u64
s3u64

Constructors

static from_seed(seed: u64) -> Rng;

Seed deterministically from a single 64-bit value. The same seed always produces the same sequence.

static from_os() -> Rng;

Seed from the OS CSPRNG. Falls back to a monotonic-clock + pid mix if the kernel source is briefly unavailable, so it never hard-fails. (The fallback is fine for non-crypto use; for cryptography use SecureRng.) Routes through secure::fill_secure_bytes so the OS source is portable - getrandom on UNIX, RtlGenRandom on Windows - instead of binding the Linux-only getrandom symbol directly.

Trait implementations

implement trait RandomSource for struct Rng