Skip to content

std.rand

xorshift64* prng; same seed, same sequence; not for crypto

pub Rng :: struct {
state: u64,
}
pub seed :: fn(s: u64) -> Rng

generator from a seed; 0 is remapped to a valid state

pub next_u64 :: fn(self: *Rng) -> u64

next raw u64; advances the state

pub next_u32 :: fn(self: *Rng) -> u32
pub next_f32 :: fn(self: *Rng) -> f32

float in [0, 1), 24-bit mantissa

pub range_i32 :: fn(self: *Rng, lo: i32, hi: i32) -> i32

uniform int in [lo, hi); lo if empty

pub range_f32 :: fn(self: *Rng, lo: f32, hi: f32) -> f32

float in [lo, hi)

pub chance :: fn(self: *Rng, p: f32) -> bool

true with probability p, clamped to 0..1

pub sign :: fn(self: *Rng) -> f32

-1 or +1

pub below :: fn(self: *Rng, n: u64) -> u64

uniform int in [0, n), unbiased (rejection); 0 if n is 0

pub range_u64 :: fn(self: *Rng, lo: u64, hi: u64) -> u64

uniform int in [lo, hi); lo if empty

pub next_f64 :: fn(self: *Rng) -> f64

float in [0, 1), 53-bit mantissa

pub fill_bytes :: fn(self: *Rng, out: []u8)
pub shuffle :: fn($T: type, self: *Rng, xs: []T)

uniform shuffle, fisher-yates

pub choose :: fn($T: type, self: *Rng, xs: []const T) -> ?T

uniform pick; null if empty