11 releases (3 stable)
Uses old Rust 2015
1.1.1 | Jan 17, 2018 |
---|---|
1.1.0 | Feb 23, 2017 |
1.0.0 | Jan 20, 2017 |
0.3.0 | May 30, 2015 |
0.1.0 | Feb 2, 2015 |
#37 in #rng
557 downloads per month
Used in 256 crates
(3 directly)
89KB
1.5K
SLoC
Mersenne Twister in Rust
This is a pure rust port of the Mersenne Twister pseudorandom number generators. See the rustdoc for suggested usage.
Algorithms
- MT19937 (32-bit version)
- MT19937-64 (64-bit version)
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT) at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
lib.rs
:
Mersenne Twister
A pure rust port of the Mersenne Twister pseudorandom number generator.
THESE ALGORITHMS ARE NOT APPROPRIATE FOR CRYPTOGRAPHIC USE.
After observing a couple hundred outputs, it is possible to
predict all future outputs. This library even implements a
recover
constructor to reconstruct the RNG state from output
samples.
Usage
If your application does not require a specific Mersenne Twister
flavor (32-bit or 64-bit), you can use the default flavor for your
target platform by using the MersenneTwister
type
definition. Either flavor accepts a u64
seed.
extern crate mersenne_twister;
extern crate rand;
use mersenne_twister::MersenneTwister;
use rand::{Rng, SeedableRng};
fn main() {
// Get a seed somehow.
let seed: u64 = 0x123456789abcdef;
// Create the default RNG.
let mut rng: MersenneTwister = SeedableRng::from_seed(seed);
// start grabbing randomness from rng...
}
Or if you want to use the default (fixed) seeds that are specified in the reference implementations:
use std::default::Default;
let mut rng: MersenneTwister = Default::default();
Portability
Note that MT19937
and MT19937_64
are not identical
algorithms, despite their similar names. They produce different
output streams from the same seed. You will need to pick a
specific flavor of the two algorithms if portable reproducibility
is important to you.
Dependencies
~330–560KB