Skip to content

Commit e84a7ea

Browse files
committed
(ml5717) Fixed U(0.0, 1.0) generation from random u64
1 parent 6ce90e4 commit e84a7ea

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

necsim-impls-no-std/src/rng/wyrng.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ pub struct WyRng(WyRand);
66
#[contract_trait]
77
impl necsim_core::rng::Core for WyRng {
88
fn sample_uniform(&mut self) -> f64 {
9+
// U(0.0, 1.0) generation from:
10+
// http://prng.di.unimi.it -> Generating uniform doubles in the unit interval
911
#[allow(clippy::cast_precision_loss)]
10-
(self.0.generate_range(0_u64, u64::MAX) as f64)
11-
/ #[allow(clippy::cast_precision_loss)]
12-
(u64::MAX as f64)
12+
((self.0.generate::<u64>() >> 11) as f64)
13+
* f64::from_bits(0x3CA0_0000_0000_0000_u64) //0x1.0p-53
1314
}
1415
}
1516

0 commit comments

Comments
 (0)