Skip to content

Commit

Permalink
use little endian for seed bytes init
Browse files Browse the repository at this point in the history
  • Loading branch information
mztikk committed Jun 30, 2023
1 parent 3ac9261 commit 7360f33
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/mt19937.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ impl SeedableRng for MT19937 {
type Seed = [u8; 4];

fn from_seed(seed: Self::Seed) -> Self {
MT19937::new_with_seed(u32::from_be_bytes(seed))
MT19937::new_with_seed(u32::from_le_bytes(seed))
}
}

Expand Down Expand Up @@ -800,4 +800,18 @@ mod tests {
let sync = mt.sync(&state_zeroes, N + 1);
assert!(sync.is_none());
}

#[cfg(feature = "rand")]
#[test]
fn test_seed() {
use rand_core::SeedableRng;

const SEED: u32 = 55555;
let mut mt = super::MT19937::new_with_seed(SEED);
assert_eq!(mt.genrand(), 554499473);
assert_eq!(mt.genrand(), 460270059);
let mut mt = super::MT19937::from_seed(SEED.to_le_bytes());
assert_eq!(mt.genrand(), 554499473);
assert_eq!(mt.genrand(), 460270059);
}
}

0 comments on commit 7360f33

Please sign in to comment.