1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
// src/lib.rs // // Copyright (c) 2015,2017 rust-mersenne-twister developers // // Licensed under the Apache License, Version 2.0 // <LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0> or the MIT // license <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your // option. All files in the project carrying such notice may not be copied, // modified, or distributed except according to those terms. //! # 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 mersenne_twister::MersenneTwister; //! 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. #![deny(missing_docs)] extern crate rand; pub use mt19937::MT19937; pub use mt19937_64::MT19937_64; mod mt19937; mod mt19937_64; /// The most platform-appropriate Mersenne Twister flavor. #[cfg(target_pointer_width = "32")] pub type MersenneTwister = MT19937; /// The most platform-appropriate Mersenne Twister flavor. #[cfg(target_pointer_width = "64")] pub type MersenneTwister = MT19937_64;