Move gen_res53 to mersenne.rs

This commit is contained in:
Noah
2020-02-03 18:27:35 -06:00
parent b40dcb7748
commit a762bf89d9
2 changed files with 9 additions and 10 deletions

View File

@@ -77,7 +77,7 @@ impl PyRandom {
#[pymethod]
fn random(&self) -> f64 {
gen_res53(&mut *self.rng.borrow_mut())
mersenne::gen_res53(&mut *self.rng.borrow_mut())
}
#[pymethod]
@@ -127,12 +127,3 @@ pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
"Random" => PyRandom::make_class(ctx),
})
}
// taken from the translated mersenne twister
/* generates a random number on [0,1) with 53-bit resolution*/
fn gen_res53<R: RngCore>(rng: &mut R) -> f64 {
let a = rng.next_u32() >> 5;
let b = rng.next_u32() >> 6;
(a as f64 * 67108864.0 + b as f64) * (1.0 / 9007199254740992.0)
}
/* These real versions are due to Isaku Wada, 2002/01/09 added */

View File

@@ -186,6 +186,14 @@ impl MT19937 {
}
}
/* generates a random number on [0,1) with 53-bit resolution*/
pub fn gen_res53<R: rand::RngCore>(rng: &mut R) -> f64 {
let a = rng.next_u32() >> 5;
let b = rng.next_u32() >> 6;
(a as f64 * 67108864.0 + b as f64) * (1.0 / 9007199254740992.0)
}
/* These real versions are due to Isaku Wada, 2002/01/09 added */
impl rand::RngCore for MT19937 {
fn next_u32(&mut self) -> u32 {
self.gen_u32()