2023-02-14 00:56:28 +00:00
|
|
|
//! We don't use `rand`, as that's too many things for us.
|
|
|
|
//!
|
2023-02-15 11:23:13 +00:00
|
|
|
//! We currently use oorandom instead, but it's missing these two utilities.
|
|
|
|
//! Perhaps we should switch to `fastrand`, or our own small PRNG, it's not like
|
|
|
|
//! we need anything more complicated than xor-shift.
|
2023-02-14 00:56:28 +00:00
|
|
|
|
|
|
|
pub fn shuffle<T>(slice: &mut [T], mut rand_index: impl FnMut(usize) -> usize) {
|
|
|
|
let mut remaining = slice.len() - 1;
|
|
|
|
while remaining > 0 {
|
|
|
|
let index = rand_index(remaining);
|
|
|
|
slice.swap(remaining, index);
|
|
|
|
remaining -= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn seed() -> u64 {
|
|
|
|
use std::hash::{BuildHasher, Hasher};
|
2024-02-01 15:16:38 +00:00
|
|
|
#[allow(clippy::disallowed_types)]
|
|
|
|
std::collections::hash_map::RandomState::new().build_hasher().finish()
|
2023-02-14 00:56:28 +00:00
|
|
|
}
|