From cb01d1aaeadd5479136802c75bb7e393815e638d Mon Sep 17 00:00:00 2001 From: Nathan Vegdahl Date: Wed, 17 Aug 2022 12:13:29 -0700 Subject: [PATCH] Add an f32() method to Rng. --- sub_crates/rrand/src/lib.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sub_crates/rrand/src/lib.rs b/sub_crates/rrand/src/lib.rs index cf3bd03..5a6e83c 100644 --- a/sub_crates/rrand/src/lib.rs +++ b/sub_crates/rrand/src/lib.rs @@ -58,6 +58,12 @@ impl Rng { let t = (self.state as u128).wrapping_mul(self.state as u128 ^ 0xe7037ed1a0b428db); ((t >> 64) ^ t) as u64 } + + /// Returns a random f32 in [0.0, 1.0). + #[inline(always)] + pub fn f32(&mut self) -> f32 { + u32_to_f32_norm(self.u32()) + } } //-------------------------------------------------------------