MCPcopy Create free account
hub / github.com/PerroEngine/Perro / shuffle

Function shuffle

perro_source/api_modules/perro_modules/src/random.rs:322–332  ·  view source on GitHub ↗
(seed: u32, values: &mut [T])

Source from the content-addressed store, hash-verified

320
321#[inline]
322pub fn shuffle<T>(seed: u32, values: &mut [T]) {
323 if values.len() < 2 {
324 return;
325 }
326
327 let mut rng = SeededRng::new(seed);
328 for i in (1..values.len()).rev() {
329 let j = ((rng.next_u32() as u64 * (i as u64 + 1)) >> 32) as usize;
330 values.swap(i, j);
331 }
332}
333
334#[derive(Debug, Clone, Copy, PartialEq, Eq)]
335pub struct SeededRng {

Calls 2

next_u32Method · 0.80
lenMethod · 0.45