Lyric v2.7.0

std.random

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.

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:20

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:78

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:88