mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-07-15 02:58:12 +00:00
12 lines
266 B
Rust
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);
|
|
}
|
|
}
|