Touch up changes around advancing feature
* Add additional comments on how to use the advance() function * Use clone() for clarity instead of reusing a seed * Compare the generator as a whole as opposed the next value in unit tests
This commit is contained in:
@@ -49,6 +49,9 @@ impl Lcg128Xsl64 {
|
||||
///
|
||||
/// Even though delta is an unsigned integer, we can pass a
|
||||
/// signed integer to go backwards, it just goes "the long way round".
|
||||
///
|
||||
/// Using this function is equivalent to calling `next_64()` `delta`
|
||||
/// number of times.
|
||||
#[inline]
|
||||
pub fn advance(&mut self, delta: u128) {
|
||||
let mut acc_mult: u128 = 1;
|
||||
@@ -178,6 +181,9 @@ impl Mcg128Xsl64 {
|
||||
///
|
||||
/// Even though delta is an unsigned integer, we can pass a
|
||||
/// signed integer to go backwards, it just goes "the long way round".
|
||||
///
|
||||
/// Using this function is equivalent to calling `next_64()` `delta`
|
||||
/// number of times.
|
||||
#[inline]
|
||||
pub fn advance(&mut self, delta: u128) {
|
||||
let mut acc_mult: u128 = 1;
|
||||
|
||||
@@ -49,6 +49,9 @@ impl Lcg64Xsh32 {
|
||||
///
|
||||
/// Even though delta is an unsigned integer, we can pass a
|
||||
/// signed integer to go backwards, it just goes "the long way round".
|
||||
///
|
||||
/// Using this function is equivalent to calling `next_32()` `delta`
|
||||
/// number of times.
|
||||
#[inline]
|
||||
pub fn advance(&mut self, delta: u64) {
|
||||
let mut acc_mult: u64 = 1;
|
||||
|
||||
@@ -5,12 +5,12 @@ use rand_pcg::{Lcg128Xsl64, Pcg64};
|
||||
fn test_lcg128xsl64_advancing() {
|
||||
let seed = Default::default();
|
||||
let mut rng1 = Lcg128Xsl64::from_seed(seed);
|
||||
let mut rng2 = Lcg128Xsl64::from_seed(seed);
|
||||
let mut rng2 = rng1.clone();
|
||||
for _ in 0..20 {
|
||||
rng1.next_u64();
|
||||
}
|
||||
rng2.advance(20);
|
||||
assert_eq!(rng1.next_u64(), rng2.next_u64());
|
||||
assert_eq!(rng1, rng2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -5,12 +5,12 @@ use rand_pcg::{Lcg64Xsh32, Pcg32};
|
||||
fn test_lcg64xsh32_advancing() {
|
||||
let seed = Default::default();
|
||||
let mut rng1 = Lcg64Xsh32::from_seed(seed);
|
||||
let mut rng2 = Lcg64Xsh32::from_seed(seed);
|
||||
let mut rng2 = rng1.clone();
|
||||
for _ in 0..20 {
|
||||
rng1.next_u32();
|
||||
}
|
||||
rng2.advance(20);
|
||||
assert_eq!(rng1.next_u32(), rng2.next_u32());
|
||||
assert_eq!(rng1, rng2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -5,12 +5,12 @@ use rand_pcg::{Mcg128Xsl64, Pcg64Mcg};
|
||||
fn test_mcg128xsl64_advancing() {
|
||||
let seed = Default::default();
|
||||
let mut rng1 = Mcg128Xsl64::from_seed(seed);
|
||||
let mut rng2 = Mcg128Xsl64::from_seed(seed);
|
||||
let mut rng2 = rng1.clone();
|
||||
for _ in 0..20 {
|
||||
rng1.next_u64();
|
||||
}
|
||||
rng2.advance(20);
|
||||
assert_eq!(rng1.next_u64(), rng2.next_u64());
|
||||
assert_eq!(rng1, rng2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user