Rename rng::next to rng::gen

This commit is contained in:
Gwilym Kuiper 2022-04-11 22:07:31 +01:00
parent 7ad52a2974
commit dc62ba4467
4 changed files with 20 additions and 20 deletions

View file

@ -961,9 +961,9 @@ mod test {
let mut answers: [Option<i32>; 128] = [None; 128];
for _ in 0..5_000 {
let command = rng.next().rem_euclid(2);
let key = rng.next().rem_euclid(answers.len() as i32);
let value = rng.next();
let command = rng.gen().rem_euclid(2);
let key = rng.gen().rem_euclid(answers.len() as i32);
let value = rng.gen();
match command {
0 => {

View file

@ -32,7 +32,7 @@ impl RandomNumberGenerator {
}
/// Returns the next value for the random number generator
pub fn next(&mut self) -> i32 {
pub fn gen(&mut self) -> i32 {
let result = (self.state[0].wrapping_add(self.state[3]))
.rotate_left(7)
.wrapping_mul(9);
@ -54,8 +54,8 @@ static GLOBAL_RNG: Mutex<RefCell<RandomNumberGenerator>> =
Mutex::new(RefCell::new(RandomNumberGenerator::new()));
/// Using a global random number generator, provides the next random number
pub fn next() -> i32 {
free(|cs| GLOBAL_RNG.borrow(*cs).borrow_mut().next())
pub fn gen() -> i32 {
free(|cs| GLOBAL_RNG.borrow(*cs).borrow_mut().gen())
}
#[cfg(test)]
@ -69,7 +69,7 @@ mod test {
let mut rng = RandomNumberGenerator::new();
for _ in 0..500 {
values[(rng.next().rem_euclid(16)) as usize] += 1;
values[(rng.gen().rem_euclid(16)) as usize] += 1;
}
for (i, &value) in values.iter().enumerate() {
@ -87,7 +87,7 @@ mod test {
let mut values: [u32; 16] = Default::default();
for _ in 0..500 {
values[super::next().rem_euclid(16) as usize] += 1;
values[super::gen().rem_euclid(16) as usize] += 1;
}
for (i, &value) in values.iter().enumerate() {

View file

@ -1115,7 +1115,7 @@ impl MiniFlameData {
self.sprite_offset = 0;
self.state = MiniFlameState::Dead;
if rng::next() % 4 == 0 {
if rng::gen() % 4 == 0 {
instruction = UpdateInstruction::CreateParticle(
ParticleData::new_health(),
entity.position,
@ -1138,7 +1138,7 @@ impl MiniFlameData {
self.sprite_offset = 0;
self.state = MiniFlameState::Dead;
if rng::next() % 4 == 0 {
if rng::gen() % 4 == 0 {
instruction = UpdateInstruction::CreateParticle(
ParticleData::new_health(),
entity.position,
@ -1703,7 +1703,7 @@ impl<'a> Boss<'a> {
Self {
entity,
health: 5,
target_location: rng::next().rem_euclid(5) as u8,
target_location: rng::gen().rem_euclid(5) as u8,
state: BossActiveState::Damaged(60),
timer: 0,
screen_coords,
@ -1804,9 +1804,9 @@ impl<'a> Boss<'a> {
fn commit(&mut self, offset: Vector2D<Number>) {
let shake = if self.shake_magnitude != 0.into() {
(
Number::from_raw(rng::next()).rem_euclid(self.shake_magnitude)
Number::from_raw(rng::gen()).rem_euclid(self.shake_magnitude)
- self.shake_magnitude / 2,
Number::from_raw(rng::next()).rem_euclid(self.shake_magnitude)
Number::from_raw(rng::gen()).rem_euclid(self.shake_magnitude)
- self.shake_magnitude / 2,
)
.into()
@ -1819,8 +1819,8 @@ impl<'a> Boss<'a> {
}
fn explode(&self, enemies: &mut Arena<Enemy<'a>>, object_controller: &'a ObjectController) {
for _ in 0..(6 - self.health) {
let x_offset: Number = Number::from_raw(rng::next()).rem_euclid(2.into()) - 1;
let y_offset: Number = Number::from_raw(rng::next()).rem_euclid(2.into()) - 1;
let x_offset: Number = Number::from_raw(rng::gen()).rem_euclid(2.into()) - 1;
let y_offset: Number = Number::from_raw(rng::gen()).rem_euclid(2.into()) - 1;
let mut flame = Enemy::new(
object_controller,
EnemyData::MiniFlame(MiniFlameData::new()),
@ -1833,7 +1833,7 @@ impl<'a> Boss<'a> {
fn get_next_target_location(&self) -> u8 {
loop {
let a = rng::next().rem_euclid(5) as u8;
let a = rng::gen().rem_euclid(5) as u8;
if a != self.target_location {
break a;
}
@ -1978,8 +1978,8 @@ impl<'a> Game<'a> {
if self.shake_time > 0 {
let size = self.shake_time.min(4) as i32;
let offset: Vector2D<Number> = (
Number::from_raw(rng::next()) % size - Number::new(size) / 2,
Number::from_raw(rng::next()) % size - Number::new(size) / 2,
Number::from_raw(rng::gen()) % size - Number::new(size) / 2,
Number::from_raw(rng::gen()) % size - Number::new(size) / 2,
)
.into();
this_frame_offset += offset;
@ -2296,7 +2296,7 @@ fn game_with_level(gba: &mut agb::Gba) {
}
}
rng::next(); // advance RNG to make it less predictable between runs
rng::gen(); // advance RNG to make it less predictable between runs
};
game.clear(&mut vram);

View file

@ -85,7 +85,7 @@ impl<'a> Sfx<'a> {
}
pub fn jump(&mut self) {
let r = rng::next() % 3;
let r = rng::gen() % 3;
let channel = match r {
0 => SoundChannel::new(JUMP1),