Skip to content

Commit 159d4e2

Browse files
committed
Move the mt19937 algorithm into its own crate
1 parent 199c75b commit 159d4e2

4 files changed

Lines changed: 15 additions & 216 deletions

File tree

Cargo.lock

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vm/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ num-iter = "0.1.39"
3333
rand = { version = "0.7", features = ["wasm-bindgen"] }
3434
rand_core = "0.5"
3535
getrandom = { version = "0.1", features = ["wasm-bindgen"] }
36+
mt19937 = "1.0"
3637
log = "0.4"
3738
rustpython-derive = {path = "../derive", version = "0.1.1"}
3839
rustpython-parser = {path = "../parser", optional = true, version = "0.1.1"}

vm/src/stdlib/random.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,10 @@ use crate::obj::objtype::PyClassRef;
1212
use crate::pyobject::{PyClassImpl, PyObjectRef, PyRef, PyResult, PyValue};
1313
use crate::VirtualMachine;
1414

15-
mod mersenne;
16-
1715
#[derive(Debug)]
1816
enum PyRng {
1917
Std(rand::rngs::ThreadRng),
20-
MT(Box<mersenne::MT19937>),
18+
MT(Box<mt19937::MT19937>),
2119
}
2220

2321
impl Default for PyRng {
@@ -77,7 +75,7 @@ impl PyRandom {
7775

7876
#[pymethod]
7977
fn random(&self) -> f64 {
80-
mersenne::gen_res53(&mut *self.rng.borrow_mut())
78+
mt19937::gen_res53(&mut *self.rng.borrow_mut())
8179
}
8280

8381
#[pymethod]
@@ -89,7 +87,7 @@ impl PyRandom {
8987
if cfg!(target_endian = "big") {
9088
key.reverse();
9189
}
92-
PyRng::MT(Box::new(mersenne::MT19937::new_with_slice_seed(&key)))
90+
PyRng::MT(Box::new(mt19937::MT19937::new_with_slice_seed(&key)))
9391
}
9492
};
9593

vm/src/stdlib/random/mersenne.rs

Lines changed: 0 additions & 211 deletions
This file was deleted.

0 commit comments

Comments
 (0)