-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not eagerly call
next_uNN
in fill_bytes
with empty remainder
Fix a bug where random numbers are consumed from the Mersenne Twister even when they will never be used because the remainder from the chunks iterator in `fill_bytes` is non-empty. This regression was introduced in: - #116 Add a basic smoke check for reproducibility with MRI's RNG pulled from `spinoso-random` in artichoke/artichoke.
- Loading branch information
Showing
3 changed files
with
42 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use rand_mt::Mt; | ||
|
||
// ```ruby | ||
// # Should double check this is official spec | ||
// it "returns the same numeric output for a given seed across all implementations and platforms" do | ||
// rnd = Random.new(33) | ||
// rnd.bytes(2).should == "\x14\\" | ||
// rnd.bytes(1000) # skip some | ||
// rnd.bytes(2).should == "\xA1p" | ||
// end | ||
// | ||
// it "returns the same numeric output for a given huge seed across all implementations and platforms" do | ||
// rnd = Random.new(bignum_value ** 4) | ||
// rnd.bytes(2).should == "_\x91" | ||
// rnd.bytes(1000) # skip some | ||
// rnd.bytes(2).should == "\x17\x12" | ||
// end | ||
// ``` | ||
#[test] | ||
fn spec_bytes() { | ||
let mut rng = Mt::new(33); | ||
let mut buf = [0; 2]; | ||
rng.fill_bytes(&mut buf); | ||
assert_eq!(buf[..], b"\x14\\"[..]); | ||
|
||
let mut skip = [0; 1000]; | ||
rng.fill_bytes(&mut skip); | ||
|
||
let mut buf = [0; 2]; | ||
rng.fill_bytes(&mut buf); | ||
assert_eq!(buf[..], b"\xA1p"[..]); | ||
} |