Expand description
§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.
Structs§
- MT19937
- The 32-bit flavor of the Mersenne Twister pseudorandom number generator.
- MT19937_
64 - The 64-bit flavor of the Mersenne Twister pseudorandom number generator.
Type Aliases§
- Mersenne
Twister - The most platform-appropriate Mersenne Twister flavor.