Challenge 23 eod.

This commit is contained in:
2022-08-04 17:13:38 -04:00
parent 8482db0bac
commit 92c73fb125
3 changed files with 73 additions and 7 deletions

View File

@@ -18,8 +18,12 @@ impl MT19937 {
mt
}
pub fn splice(&mut self, state: Vec<u32>) {
self.mt = state;
self.index = 624;
}
pub fn seed(&mut self, seed: u32) {
self.index = N;
const F: u32 = 1812433253;
self.mt[0] = seed;
for i in 1..N {
@@ -27,14 +31,14 @@ impl MT19937 {
+ Wrapping(i as u32))
.0;
}
self.twist();
}
pub fn extract_number(&mut self) -> u32 {
if self.index >= N {
if self.index > N {
panic!("Generator was never seeded");
}
if self.index == N {
self.twist();
} else if self.index > N {
panic!("Generator was never seeded");
}
const S: u32 = 7;