1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-07-15 02:58:12 +00:00
trezor-firmware/core/embed/rust/src/trezorhal/random.rs
2022-06-08 14:42:04 +02:00

12 lines
266 B
Rust

pub fn uniform(n: u32) -> u32 {
unsafe { super::ffi::random_uniform(n) }
}
pub fn shuffle<T>(slice: &mut [T]) {
// Fisher-Yates shuffle.
for i in (1..slice.len()).rev() {
let j = uniform(i as u32 + 1) as usize;
slice.swap(i, j);
}
}