extern crate pcg_rand; extern crate rand; use pcg_rand::seeds::PcgSeeder; use pcg_rand::Pcg32Basic; use rand::{distributions::Alphanumeric, Rng, SeedableRng}; #[test] fn pcg_basic_unseeded() { let mut ra: Pcg32Basic = Pcg32Basic::new_unseeded(); let mut rb: Pcg32Basic = Pcg32Basic::new_unseeded(); assert_eq!( ra.sample_iter(&Alphanumeric).take(100).collect::>(), rb.sample_iter(&Alphanumeric).take(100).collect::>() ); } #[test] fn pcg_basic_seed_match() { let mut ra: Pcg32Basic = SeedableRng::from_seed(PcgSeeder::seed_with_stream(11, 12)); let mut rb: Pcg32Basic = SeedableRng::from_seed(PcgSeeder::seed_with_stream(11, 12)); assert_eq!( ra.sample_iter(&Alphanumeric).take(100).collect::>(), rb.sample_iter(&Alphanumeric).take(100).collect::>() ); } #[test] fn pcg_basic_seq_diff() { //Test a bad case same seed with just slightly different //sequences (They must be 2 apart because they get incremented to odd //numbers for generator properties) let mut ra: Pcg32Basic = SeedableRng::from_seed(PcgSeeder::seed_with_stream(11, 12)); let mut rb: Pcg32Basic = SeedableRng::from_seed(PcgSeeder::seed_with_stream(11, 14)); assert!( ra.sample_iter(&Alphanumeric).take(100).collect::>() != rb.sample_iter(&Alphanumeric).take(100).collect::>() ); } #[test] #[should_panic] fn pcg_basic_seq_aliasing() { //Test a bad case same seed with just slightly different //sequences. These two end up being the same because 12 gets bumped //to 13 or the generator doesn't fill the entire range (needs a 1 //in the lowest bit) //This is only a trait of PCGBasic not the other generators let mut ra: Pcg32Basic = SeedableRng::from_seed(PcgSeeder::seed_with_stream(11, 12)); let mut rb: Pcg32Basic = SeedableRng::from_seed(PcgSeeder::seed_with_stream(11, 13)); assert!( ra.sample_iter(&Alphanumeric).take(100).collect::>() != rb.sample_iter(&Alphanumeric).take(100).collect::>() ); } #[test] fn pcg_basic_seed_diff() { //Test a bad case same seed with just slightly different //seeds let mut ra: Pcg32Basic = SeedableRng::from_seed(PcgSeeder::seed_with_stream(11, 11)); let mut rb: Pcg32Basic = SeedableRng::from_seed(PcgSeeder::seed_with_stream(12, 11)); assert!( ra.sample_iter(&Alphanumeric).take(100).collect::>() != rb.sample_iter(&Alphanumeric).take(100).collect::>() ); }