You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
SliceRandom.shuffle produces a different result in 0.9 than in 0.8 #1580
SliceRandom's shuffle function was reimplemented in 0.9, and it produces a different result when using a deterministic PRNG.
I expect rand's functions to preserve results from one release to the next, for deterministic PRNGs.
Code samples
0.8 version
/// The pseudo-random number generator we use.pubtypeRandom = rand_pcg::Pcg64Mcg;/// Constructs a new Random from a given string seed.pubfnnew_random(seed:&str) -> Random{
rand_seeder::Seeder::from(seed).make_rng()}#[cfg(test)]mod tests {use rand::seq::SliceRandom;usesuper::*;#[test]fntest_random(){letmut rng = new_random("test");letmut nums = [1,2,3,4,5];
nums.shuffle(&mut rng);assert_eq!(nums,[4,3,1,5,2]);}}
0.9 version
/// The pseudo-random number generator we use.pubtypeRandom = rand_pcg::Pcg64Mcg;/// Constructs a new Random from a given string seed.pubfnnew_random(seed:&str) -> Random{
rand_seeder::Seeder::from(seed).into_rng()}#[cfg(test)]mod tests {use rand::seq::SliceRandom;usesuper::*;#[test]fntest_random(){letmut rng = new_random("test");letmut nums = [1,2,3,4,5];
nums.shuffle(&mut rng);// assert_eq!(nums, [4, 3, 1, 5, 2]); -- this fails. The new shuffle produces this other sequence:assert_eq!(nums,[5,1,3,2,4]);}}
Activity
dhardy commentedon Feb 7, 2025
The CHANGELOG mentions:
Our reproducibility policy permits value-breaking changes in v0.9. Not what you want to hear, I know, but we do actually have a policy on this stuff.