extern crate alloc;
use alloc::vec::Vec;
#[cfg(feature = "rand-0_8")]
use rand_0_8 as rand;
#[cfg(feature = "rand-0_9")]
use rand_0_9 as rand;
use crate::shuffler::Shuffler;
#[derive(Debug, Default)]
pub struct FisherYates {}
impl<T> Shuffler<T> for FisherYates {
fn shuffle<R>(&mut self, data: &mut Vec<T>, rng: &mut R) -> Result<(), &str>
where
T: Clone,
R: rand::Rng + ?Sized,
{
for i in (1..data.len()).rev() {
#[cfg(feature = "rand-0_8")]
let j = rng.gen_range(0..(i + 1));
#[cfg(feature = "rand-0_9")]
let j = rng.random_range(0..(i + 1));
data.swap(i, j);
}
Ok(())
}
}