std.random
Random numbers:
import std.random
let die = random.int(1, 7) // 1 to 6
let x = random.float() // 0 up to 1
let card = random.choice(cards) // Option
let deck = random.shuffle(cards)The numbers are not for passwords or keys. random.seed(n) makes the numbers that follow the same on every run, for tests; without it they differ each time.
Functions
fn seed
pub fn seed(n: i64)Makes the numbers that follow repeatable.
fn int
pub fn int(low: i64, high: i64) -> i64A whole number from low up to, but not including, high, each as likely, like the range low..high. low when high <= low.
fn float
pub fn float() -> f64A number from 0 up to, but not including, 1.
fn bool
pub fn bool() -> booltrue or false, each half of the time.
fn choice
pub fn choice[T](xs: List[T]) -> Option[T]A random element of xs, or None when it is empty.
fn shuffle
pub fn shuffle[T](xs: List[T]) -> List[T]A copy of xs in random order (every order as likely).