apiculture/random

Values

pub fn random_bytes(count: Int) -> Result(BitArray, error.Error)

Generates cryptographically secure random bytes.

On Erlang: Uses crypto:strong_rand_bytes/1 On JavaScript: Uses crypto.getRandomValues() (Web Crypto API)

Returns an error if secure randomness is unavailable.

pub fn random_chars(
  alphabet alphabet: alphabet.Alphabet,
  count count: Int,
) -> Result(List(Int), error.Error)

Generates cryptographically secure random characters by sampling directly from an alphabet using rejection sampling to avoid modulo bias.

This is mathematically distinct from generating random bytes and then encoding them - this samples characters directly from the alphabet.

Search Document