Skip to main content

random_bytes

Function random_bytes 

Source
pub fn random_bytes<const N: usize>() -> [u8; N]
Expand description

Generates N bytes of mixed entropy.

For requests <= 32 bytes, returns a truncated output from random_bytes_mixed(). For larger requests, generates multiple 32-byte blocks with unique counters.

§Panics

Panics if the RNG health check fails. Production code MUST use try_random_bytes and propagate the error instead — a CSPRNG failure is a fail-closed condition, not a crash. This panicking convenience is for tests, benchmarks, and non-fallible contexts only (#jrec: all production callers were migrated to try_random_bytes).