mirror of
https://github.com/italicsjenga/agb.git
synced 2024-12-25 01:01:34 +11:00
Move the random number generator to a crate level thing
This commit is contained in:
parent
1982df727c
commit
9752377a15
|
@ -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 {
|
struct NoisyDrop {
|
||||||
i: i32,
|
i: i32,
|
||||||
dropped: bool,
|
dropped: bool,
|
||||||
|
@ -985,7 +956,7 @@ mod test {
|
||||||
#[test_case]
|
#[test_case]
|
||||||
fn extreme_case(_gba: &mut Gba) {
|
fn extreme_case(_gba: &mut Gba) {
|
||||||
let mut map = HashMap::new();
|
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];
|
let mut answers: [Option<i32>; 128] = [None; 128];
|
||||||
|
|
||||||
|
|
|
@ -153,6 +153,8 @@ pub mod mgba;
|
||||||
pub use agb_fixnum as fixnum;
|
pub use agb_fixnum as fixnum;
|
||||||
/// Contains an implementation of a hashmap which suits the gameboy advance's hardware.
|
/// Contains an implementation of a hashmap which suits the gameboy advance's hardware.
|
||||||
pub mod hash_map;
|
pub mod hash_map;
|
||||||
|
/// Simple random number generator
|
||||||
|
pub mod rng;
|
||||||
mod single;
|
mod single;
|
||||||
/// Implements sound output.
|
/// Implements sound output.
|
||||||
pub mod sound;
|
pub mod sound;
|
||||||
|
|
Loading…
Reference in a new issue