Skip to content

@random

Import this module with import @random.

Function Signature Description
rand_f64 () -> f64 Random f64 [0.0, 1.0)
rand_f64 (min f64, max f64) -> f64 Random f64 [min, max); panics if min is not less than max
rand_i64 (min i64, max i64) -> i64 Random i64 [min, max); panics if min is not less than max
rand_bool () -> bool Random boolean
rand_u8 () -> u8 Random u8 [0, 255]
rand_char () -> char Random printable char
rand_char (min char, max char) -> char Random char [min, max), never a surrogate (U+D800–U+DFFF); panics if min is not less than max or the range holds only surrogates
rand_string (length i64, alphabet string) -> string String of length characters drawn uniformly from alphabet; length 0 returns ""; panics if alphabet is empty and length > 0
rand_bytes (n i64) -> [u8] n random bytes from the module’s RNG (reproducible with seed, not cryptographically secure); n 0 returns an empty array; panics if n is negative
roll_dice (count i64, sides i64) -> i64 Sum of count rolls of a sides-sided die, each uniform in 1..sides; panics if count or sides is less than 1, or if the sum of the rolls exceeds i64.MAX (P0156)
choice (arr [T]) -> T Random element from array
shuffle (arr [T]) -> [T] Return shuffled copy
sample (arr [T], n i64) -> [T] Return n unique random elements
seed (value i64) Seed the random number generator