You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
trezor-firmware/core/embed/rust/src/trezorhal/random.rs

17 lines
336 B

extern "C" {
// trezor-crypto/rand.h
fn random_uniform(n: u32) -> u32;
}
pub fn uniform(n: u32) -> u32 {
unsafe { 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);
}
}