-
-
Notifications
You must be signed in to change notification settings - Fork 481
Closed
Labels
X-bugType: bug reportType: bug report
Description
Summary
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.
pub type Random = rand_pcg::Pcg64Mcg;
/// Constructs a new Random from a given string seed.
pub fn new_random(seed: &str) -> Random {
rand_seeder::Seeder::from(seed).make_rng()
}
#[cfg(test)]
mod tests {
use rand::seq::SliceRandom;
use super::*;
#[test]
fn test_random() {
let mut rng = new_random("test");
let mut 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.
pub type Random = rand_pcg::Pcg64Mcg;
/// Constructs a new Random from a given string seed.
pub fn new_random(seed: &str) -> Random {
rand_seeder::Seeder::from(seed).into_rng()
}
#[cfg(test)]
mod tests {
use rand::seq::SliceRandom;
use super::*;
#[test]
fn test_random() {
let mut rng = new_random("test");
let mut 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]);
}
}Metadata
Metadata
Assignees
Labels
X-bugType: bug reportType: bug report