logos.std.random
Module std · package logos-std
Types
structRng
struct Rng
Fast seedable pseudo-random number generator based on splitmix64.
Deterministic for a given seed; not cryptographically secure — use os_random for that.
Fields
state: u64
Methods
fn next_bool(self: &mut Rng) -> bool
Returns a pseudo-random bool, each value with probability 1/2.
fn next_f64(self: &mut Rng) -> f64
Returns a pseudo-random f64 uniform in [0.0, 1.0) with 53 bits of precision.
fn next_range_i64(self: &mut Rng, lo: i64, hi: i64) -> i64
Returns a pseudo-random i64 uniform in [lo, hi).
Caller must ensure hi > lo (hi == lo divides by zero); modulo reduction gives
negligible bias unless the span approaches 2^64.
fn next_u32(self: &mut Rng) -> u32
Returns the next pseudo-random u32 (low 32 bits of next_u64).
fn next_u64(self: &mut Rng) -> u64
Returns the next pseudo-random u64 (one raw splitmix64 step).
Functions
fnos_random
fn os_random(buf: *mut u8, len: i64) -> i64
Fills buf with len cryptographic-quality random bytes from the OS.
Returns the number of bytes written (len on success) or -1 on error.
fnos_u64
fn os_u64() -> u64
Returns a random u64 from OS entropy.
The getrandom result is unchecked; if it fails, the zero-initialized buffer yields 0.
fnrng_from_os
fn rng_from_os() -> Rng
Creates an Rng seeded from OS entropy.
fnrng_new
fn rng_new(seed: u64) -> Rng
Creates an Rng with the given seed; equal seeds yield identical sequences.