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.
9pub fn os_random<const N: usize>() -> [u8; N] {
10 let mut buf = [0u8; N];
11 getrandom::fill(&mut buf).unwrap();
12 buf
13}