Skip to content

Commit a762bf8

Browse files
committed
Move gen_res53 to mersenne.rs
1 parent b40dcb7 commit a762bf8

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

vm/src/stdlib/random.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ impl PyRandom {
7777

7878
#[pymethod]
7979
fn random(&self) -> f64 {
80-
gen_res53(&mut *self.rng.borrow_mut())
80+
mersenne::gen_res53(&mut *self.rng.borrow_mut())
8181
}
8282

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

vm/src/stdlib/random/mersenne.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,14 @@ impl MT19937 {
186186
}
187187
}
188188

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

0 commit comments

Comments
 (0)