module std::randomsource
Pseudo-random numbers: xoshiro256** (Blackman and Vigna), fast and statistically strong, not for secrets.
A generator from a seed gives the same sequence on every run and every platform, the interpreter included; one from entropy is seeded by the system's random source (alloyc/src/support/system.c).
type Randomsource
exp type Random = struct
Functions
exp fn Random::from_seed(seed: u64) -> Randomexp fn Random::from_entropy() -> Randomexp fn next(self r: &var Random) -> u64exp fn below(self r: &var Random, bound: u64) -> u64exp fn range<T: Number>(self r: &var Random, low: T, high: T) -> Texp fn unit(self r: &var Random) -> f64exp fn chance(self r: &var Random, probability: f64) -> boolexp fn shuffle<T>(self r: &var Random, items: &var [T])
fn Random::from_seedsource
exp fn Random::from_seed(seed: u64) -> Random
A generator whose sequence the seed decides, expanded by SplitMix64.
fn Random::from_entropysource
exp fn Random::from_entropy() -> Random
A generator seeded by the system's random source, or by the clock when there is none.
fn nextsource
exp fn next(self r: &var Random) -> u64
The next 64 random bits.
fn belowsource
exp fn below(self r: &var Random, bound: u64) -> u64
A number in [0, bound), every one equally likely (Lemire's method); 0 for a bound of 0.
fn rangesource
exp fn range<T: Number>(self r: &var Random, low: T, high: T) -> T
A number in [low, high), integer or float; low when the range is empty.
fn unitsource
exp fn unit(self r: &var Random) -> f64
A float in [0, 1), with 53 random bits.
fn chancesource
exp fn chance(self r: &var Random, probability: f64) -> bool
True with the given probability.
fn shufflesource
exp fn shuffle<T>(self r: &var Random, items: &var [T])
Puts the items in a random order, every order equally likely (Fisher-Yates).