Skip to content

Commit

Permalink
new methods: current_u8, next_new for mult13p1 rng
Browse files Browse the repository at this point in the history
  • Loading branch information
joseluis committed Aug 31, 2023
1 parent 0841ee1 commit 58b8f8e
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/misc/mult13p1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ impl Mult13P1 {
Self { state: seed }
}

/// Returns the current random `u8`.
#[inline(always)]
#[must_use]
pub const fn current_u8(&self) -> u8 {
self.state
}

/// Returns the next random `u8`.
#[inline]
#[must_use]
Expand All @@ -38,4 +45,16 @@ impl Mult13P1 {
self.state = n + n_times_2_pow_2 + n_times_2_pow_3 + 1;
self.state
}

/// Returns a copy of the next new random state.
#[inline]
#[must_use]
pub const fn next_new(&self) -> Self {
let mut state = self.state;
let n_times_2_pow_2 = state << 2;
let n_times_2_pow_3 = state << 3;
// 13*n = n + n*2^2 + n*2^3
state += n_times_2_pow_2 + n_times_2_pow_3 + 1;
Self { state }
}
}

0 comments on commit 58b8f8e

Please sign in to comment.