From 9752377a15e14f76ffc4c3324784b43cfca63dbf Mon Sep 17 00:00:00 2001 From: Gwilym Kuiper Date: Wed, 23 Mar 2022 21:46:59 +0000 Subject: [PATCH] Move the random number generator to a crate level thing --- agb/src/hash_map.rs | 31 +------------------------------ agb/src/lib.rs | 2 ++ 2 files changed, 3 insertions(+), 30 deletions(-) diff --git a/agb/src/hash_map.rs b/agb/src/hash_map.rs index 3a53868e..fe9ee3a6 100644 --- a/agb/src/hash_map.rs +++ b/agb/src/hash_map.rs @@ -918,35 +918,6 @@ mod test { } } - struct RandomNumberGenerator { - state: [u32; 4], - } - - impl RandomNumberGenerator { - const fn new() -> Self { - Self { - state: [1014776995, 476057059, 3301633994, 706340607], - } - } - - fn next(&mut self) -> i32 { - let result = (self.state[0].wrapping_add(self.state[3])) - .rotate_left(7) - .wrapping_mul(9); - let t = self.state[1].wrapping_shr(9); - - self.state[2] ^= self.state[0]; - self.state[3] ^= self.state[1]; - self.state[1] ^= self.state[2]; - self.state[0] ^= self.state[3]; - - self.state[2] ^= t; - self.state[3] = self.state[3].rotate_left(11); - - result as i32 - } - } - struct NoisyDrop { i: i32, dropped: bool, @@ -985,7 +956,7 @@ mod test { #[test_case] fn extreme_case(_gba: &mut Gba) { let mut map = HashMap::new(); - let mut rng = RandomNumberGenerator::new(); + let mut rng = crate::rng::RandomNumberGenerator::new(); let mut answers: [Option; 128] = [None; 128]; diff --git a/agb/src/lib.rs b/agb/src/lib.rs index 245bc690..66d8c2b8 100644 --- a/agb/src/lib.rs +++ b/agb/src/lib.rs @@ -153,6 +153,8 @@ pub mod mgba; pub use agb_fixnum as fixnum; /// Contains an implementation of a hashmap which suits the gameboy advance's hardware. pub mod hash_map; +/// Simple random number generator +pub mod rng; mod single; /// Implements sound output. pub mod sound;