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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
// src/lib.rs
//
// Copyright (c) 2015,2017 rust-mersenne-twister developers
// Copyright (c) 2020 Ryan Lopopolo <rjl@hyperbo.la>
//
// 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.
// Enable feature callouts in generated documentation:
// https://doc.rust-lang.org/beta/unstable-book/language-features/doc-cfg.html
//
// This approach is borrowed from tokio.
//! Mersenne Twister random number generators.
//!
//! This is a native Rust implementation of a selection of Mersenne Twister
//! generators. Mersenne Twister is not suitable for cryptographic use.
//!
//! This crate provides:
//!
//! - [`Mt`], the original reference Mersenne Twister implementation known as
//! `MT19937`. This is a good choice on both 32-bit and 64-bit CPUs (for
//! 32-bit output).
//! - [`Mt64`], the 64-bit variant of `MT19937` known as `MT19937-64`. This
//! algorithm produces a different output stream than `MT19937` and produces
//! 64-bit output. This is a good choice on 64-bit CPUs.
//!
//! Both of these RNGs use approximately 2.5 kilobytes of state. [`Mt`] uses a
//! 32-bit seed. [`Mt64`] uses a 64-bit seed. Both can be seeded from an
//! iterator of seeds.
//!
//! Both RNGs implement a `recover` constructor which can reconstruct the RNG
//! state from a sequence of output samples.
//!
//! # Usage
//!
//! You can seed a RNG and begin sampling it:
//!
//! ```
//! # use rand_mt::Mt64;
//! // Create the RNG.
//! let mut rng = Mt64::new(0x1234_567_89ab_cdef_u64);
//! // start grabbing randomness from rng...
//! let mut buf = vec![0; 512];
//! rng.fill_bytes(&mut buf);
//! ```
//!
//! Or if you want reproducible output from the default reference seed:
//!
//! ```
//! # use rand_mt::Mt;
//! let mut mt = Mt::new(Mt::DEFAULT_SEED);
//! assert_ne!(mt.next_u32(), mt.next_u32());
//! ```
//!
//! [`Mt::new_unseeded`] and [`Mt64::new_unseeded`] are deterministic shortcuts
//! for the reference seed. They are intended for reproducible streams and
//! tests and do not gather entropy.
//!
//! # Crate Features
//!
//! `rand_mt` is `no_std` compatible. `rand_mt` has several optional features
//! that are enabled by default:
//!
//! - **rand-traits** - Enables a dependency on [`rand_core`]. Activating this
//! feature implements `Rng` and `SeedableRng` on the RNGs in this crate.
//!
//! Mersenne Twister requires approximately 2.5 kilobytes of internal state. To
//! make the RNGs implemented in this crate practical to embed in other structs,
//! you may wish to store the RNG in a [`Box`].
//!
//! [`Box`]: https://doc.rust-lang.org/std/boxed/struct.Box.html"
extern crate std;
use fmt;
pub use crateMt;
pub use crateMt64;
/// Error returned from fallible Mersenne Twister recovery constructors.
// Ensure code blocks in `README.md` compile.
//
// This module and macro declaration should be kept at the end of the file, in
// order to not interfere with code coverage.
readme!;