Move the random number generator to a crate level thing

This commit is contained in:
Gwilym Kuiper 2022-03-23 21:46:59 +00:00
parent 1982df727c
commit 9752377a15
2 changed files with 3 additions and 30 deletions

View file

@ -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<i32>; 128] = [None; 128];

View file

@ -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;