1
0
Fork 0
mirror of https://github.com/doukutsu-rs/doukutsu-rs synced 2024-11-12 17:22:43 +00:00
doukutsu-rs/src/rng.rs

23 lines
436 B
Rust
Raw Normal View History

2020-08-20 18:31:47 +00:00
/// Stateful RNG
pub struct RNG {
pub seed: u32,
}
impl RNG {
pub fn new() -> Self {
Self {
seed: 0,
}
}
pub fn next(&mut self) -> u32 {
// MSVC LCG values
self.seed = self.seed.wrapping_mul(214013).wrapping_add(2531011);
self.seed
}
pub fn range(&mut self, start: i32, end: i32) -> i32 {
start + (self.next() % (end - start) as u32) as i32
}
}