Module rand

Module rand 

Source
Expand description

Thread-local PRNG seeded externally (raw_rand recommended).

The IC executes canister code single-threaded, so RefCell provides sufficient interior mutability without locking or poisoning semantics.

Use update calls for randomness so the PRNG state advances, and seed in init + post_upgrade via timers.

Enums§

RngError
RngError Errors raised when randomness is unavailable.

Functions§

fill_bytes
Fill the provided buffer with random bytes.
is_seeded
Returns true if the RNG has been seeded.
next_u8
Produce an 8-bit random value (derived from next_u16).
next_u16
Produce a 16-bit random value from the shared RNG.
next_u32
Produce a 32-bit random value from the shared RNG.
next_u64
Produce a 64-bit random value from the shared RNG.
next_u128
Produce a 128-bit random value from the shared RNG.
random_bytes
Produce random bytes using the shared RNG.
random_hex
Produce hex-encoded random bytes using the shared RNG.
seed_from
Seed the RNG with a 32-byte value (e.g. management canister raw_rand output).