std/random

Random, a seedable, splittable generator of random numbers that is a value: the same seed makes the same numbers on every machine and in both back ends, and a generator handed to a function is how that function gets its randomness (docs/design/RANDOM.md).

The algorithm is SplitMix64, and it is a promise: the sequence of a seed, the mapping from its bits to integers and floats, the shuffle and the split are documented, frozen and pinned by known-answer tests, so numbers recorded with one version of the toolchain are the numbers of every later one. Ordinary TorbScript over UInt64 and its wrapping arithmetic, with no native and no capability: a package that makes random values from a generator it was handed needs no permission. The operating system's source of unpredictable bytes is Entropy of std/os/entropy, and its Entropy.int64() is where a seed that nobody can repeat comes from: Random.seeded Entropy.int64().

Not for secrets. SplitMix64 is fast and passes the statistical batteries, and a generator that is seeded with 64 bits can be recovered from a few of its outputs. A key, a nonce or a token is made from Entropy.

Modules

Everything