envzn
0.8 · beta · not released

Library / System / Randomness / SecureRandom

CLASSIMPLEMENTS Random

SecureRandom

A cryptographically-secure Random drawing fresh operating-system entropy on every call (getentropy via the native shim). For tokens, session identifiers, salts, and keys. Not a PRNG: there is no seed and no reproducibility. INIT raises RandomError if the OS entropy source is unavailable.

Constructors 1

INIT()

Methods 5

METHOD boundedSecure(uint64 bound) RETURNS uint64
reads

Uniform unsigned in [0, bound) over fresh entropy — the same 128-bit Lemire rejection as the PRNG path, but each draw pulls new OS entropy rather than advancing a seeded engine. Assumes bound >= 1.

MODIFY METHOD nextInt(int64 bound) RETURNS int64
modifies

Uniform in [0, bound) over fresh entropy. bound <= 0 PANICs.

The former nextLong; see Xoshiro256.nextInt for why the two collapsed.

A checked r AS int64 was tried here and its ELSE branch had nothing to put in it, because the draw cannot reach the upper half of uint64: bound > 0 by the guard, so b <= INT64_MAX, and boundedSecure returns Lemire-uniform in [0, b) — the value is bounded BY an int64 and is therefore always one. An UNREACHABLE! in that branch would be honest but would still be a branch written for a statically-impossible case, which is what the unchecked, NAMED helper exists to avoid. toInt64 states the crossing in one line and is exact for every value this can produce.

MODIFY METHOD nextUInt128() RETURNS uint128
modifies
MODIFY METHOD nextFloat() RETURNS float64
modifies
MODIFY METHOD nextBoolean() RETURNS boolean
modifies