Lyric v4.5.0

std.random

secureRandom function

pub fn secureRandom(count: int): uint8[]

count bytes from the operating system's cryptographic source — the ONE thing in this module that is not deterministic, and deliberately so marked: keys, tokens and session ids need entropy no seed can replay, which is exactly what makes it useless for a simulation that wants to be reproduced. A negative count panics; zero answers the empty array.

Capability-free like the rest of the module: the source reaches no file, no clock and no network — an embedded host loses nothing by a guest that can draw good dice.

stdlib/std/random.lyr:25

Random class

pub class Random

A deterministic pseudo-random generator (xorshift64*): one int of state, seeded by the caller. Not cryptographic — keys need a source from the operating system, which is what secureRandom is.

state: int

The generator state; every draw replaces it.

pub static fn seeded(seed: int): Random

A generator with an explicit seed. A seed of 0 is a fixed point for xorshift — the sequence would stay 0 forever — so it is replaced silently rather than panicking on a plausible input.

pub mut fn nextInt(): int

The next raw value. It may have either sign.

pub mut fn nextIntRange(lo: int, hi: int): int

Uniformly distributed in [lo, hi). An empty range yields lo.

pub mut fn nextFloat(): float

Uniformly distributed in [0, 1).

pub mut fn nextBool(): bool

True or false, from the next draw's parity.

pub mut fn nextGaussian(): float

Normally distributed, mean 0 and deviation 1 (Box–Muller).

stdlib/std/random.lyr:38

shuffle function

pub fn shuffle<T>(random: Random, xs: List<T>): void

Shuffles in place, Fisher–Yates: every permutation equally likely, one draw per element.

stdlib/std/random.lyr:93

choice function

pub fn choice<T>(random: Random, xs: List<T>): ?T

One element drawn uniformly, or null from an empty list.

stdlib/std/random.lyr:103