Implement challenge 24 and finish set 3.

This commit is contained in:
2022-08-12 12:28:19 -04:00
parent 98ad4c7712
commit fbf26efa44
6 changed files with 145 additions and 19 deletions

View File

@@ -34,6 +34,11 @@ impl MT19937 {
self.twist();
}
pub fn extract_bytes(&mut self) -> [u8; 4] {
let n = self.extract_number();
n.to_ne_bytes()
}
pub fn extract_number(&mut self) -> u32 {
if self.index == N {
self.twist();
@@ -60,10 +65,9 @@ impl MT19937 {
fn twist(&mut self) {
const M: usize = 397;
const R: u32 = 31;
const A: u32 = 0x9908B0DF;
const LOWER_MASK: u32 = (1 << R) - 1; // 0x7fffffff
const UPPER_MASK: u32 = !LOWER_MASK; // 0x80000000
const A: u32 = 0x9908_B0DF;
const LOWER_MASK: u32 = 0x7fff_ffff;
const UPPER_MASK: u32 = 0x8000_0000;
const FIRST_HALF: usize = N - M;
for i in 0..FIRST_HALF {