Skip to main content

shuffle

Function shuffle 

Source
pub fn shuffle<T>(slice: &mut [T])
Expand description

Shuffles a slice in place (Fisher-Yates) with the default generator, so that the outcome is reproducible with seed; the slice counterpart of Vector::shuffle (igraph_vector_shuffle), which runs the same algorithm: for the same seed both produce the same permutation.

use igraph::prelude::*;
let mut a: Vec<u32> = (0..10).collect();
rng::seed(1).unwrap();
rng::shuffle(&mut a);
let mut b: Vec<u32> = (0..10).collect();
rng::seed(1).unwrap();
rng::shuffle(&mut b);
assert_eq!(a, b);
a.sort();
assert_eq!(a, (0..10).collect::<Vec<_>>());