Skip to main content

rustpython_common/
rand.rs

1/// Get `N` bytes of random data.
2///
3/// This function is mildly expensive to call, as it fetches random data
4/// directly from the OS entropy source.
5///
6/// # Panics
7///
8/// Panics if the OS entropy source returns an error.
9#[must_use]
10pub fn os_random<const N: usize>() -> [u8; N] {
11    let mut buf = [0u8; N];
12    getrandom::fill(&mut buf).unwrap();
13    buf
14}