zena:random
zena
import {…} from 'zena:random';
Random numbers from the host's cryptographically secure generator:
wasi:random's random interface on the component targets, and
crypto.getRandomValues on js.
The values are unpredictable, so they are fit for keys, salts, nonces and identifiers. Nothing seeds the generator, so a sequence cannot be repeated.
Examples ​
zena
import { randomBytes, randomInt, randomF64 } from 'zena:random';
let salt = randomBytes(32);
let roll = randomInt(1..7);
let jitter = randomF64() * 50.0;
Functions
randomBytes
zena
function randomBytes(count: i32): FixedArray<u8>
count random bytes. Throws when count is negative.
randomU64
zena
function randomU64(): u64
A random u64.
randomInt
zena
function randomInt(bound: i32): i32
A random integer at least 0 and less than bound, each equally
likely. Throws when bound is not positive.
randomInt
zena
function randomInt(range: BoundedRange): i32
A random integer in the half-open range [range.start, range.end),
each equally likely. Throws when range.start >= range.end.
randomF64
zena
function randomF64(): f64
A random f64 at least 0 and less than 1: one of the 2^53 multiples
of 2^-53 in that range, each equally likely.