std/random¶
module random
Randomness: samples, shuffles, choices, numbers and UUIDs. Each draw has
two forms. With a seed argument it is pure: its result is a function of
the seed, its input and its call site. Without one it is effectful and
draws from the evaluation seed, fixed once per evaluation from the host's
entropy or --seed. The generator is ChaCha12 and is not fit for keys,
tokens or any other secret: a seeded draw is predictable by design. Not
in the prelude: a program writes import random for
random.shuffle(…), or from random import * for shuffle(…).
sample—nelements ofselfdrawn without replacement, in their order inself; all ofselfwherenis not below its size.shuffle— The elements ofselfin a uniformly random order (Fisher–Yates).choice— One element ofselfdrawn uniformly, ornonewhereselfis empty.random_int— AnIntdrawn uniformly fromlowtohigh, both included.random_float— AFloatdrawn uniformly from0.0included to1.0excluded.uuid— A version 7 UUID: its first 48 bits are the evaluation instant's Unix milliseconds and the next 42 a counter, so the UUIDs of one evaluation sort in the order they were drawn.