Skip to content

Commit b119a4e

Browse files
committed
Update documentation
1 parent d6cc46b commit b119a4e

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

src/lib.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//! This crate was translated from the original
77
//! [implementation](http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/MT2002/emt19937ar.html)
88
//! by a team at Hiroshima University. The original content of the header of
9-
//! their implementation, along with the license, is left intact below.
9+
//! their implementation, along with the BSD-3 license, is left intact below.
1010
//!
1111
//! # mt19937ar.c header
1212
@@ -49,7 +49,9 @@
4949
5050
5151
Any feedback is very welcome.
52+
5253
http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html
54+
5355
email: m-mat @ math.sci.hiroshima-u.ac.jp (remove space)
5456
*/
5557

@@ -63,6 +65,7 @@ const MATRIX_A: u32 = 0x9908b0dfu32; /* constant vector a */
6365
const UPPER_MASK: u32 = 0x80000000u32; /* most significant w-r bits */
6466
const LOWER_MASK: u32 = 0x7fffffffu32; /* least significant r bits */
6567

68+
/// rand::Rng instance implementing the mt19937 mersenne twister algorithm
6669
pub struct MT19937 {
6770
mt: [u32; N], /* the array for the state vector */
6871
mti: usize, /* mti==N+1 means mt[N] is not initialized */
@@ -105,9 +108,9 @@ impl MT19937 {
105108
}
106109

107110
/** initialize by an array with array-length */
108-
/** init_key is the array for initializing keys */
109-
/** key_length is its length */
110-
/** slight change for C++, 2004/2/26 */
111+
/* init_key is the array for initializing keys */
112+
/* key_length is its length */
113+
/* slight change for C++, 2004/2/26 */
111114
pub fn seed_slice(&mut self, init_key: &[u32]) {
112115
let mut i;
113116
let mut j;
@@ -197,8 +200,9 @@ impl MT19937 {
197200
}
198201

199202
/** generates a random number on [0,1) with 53-bit resolution*/
203+
///
200204
/// This generates a float with the same algorithm that CPython uses; calling
201-
/// it with an `MT19937` with a given seed returns the same as it would in CPython.
205+
/// it with an [`MT19937`](struct.MT19937.html) with a given seed returns the same as it would in CPython.
202206
///
203207
/// e.g.:
204208
/// ```
@@ -216,7 +220,9 @@ impl MT19937 {
216220
/// (note that CPython converts ints to slices by taking the native endian ordering
217221
/// of the underlying "BigInt" implementation, but for seeds < u32::max_value(),
218222
/// just `&[seed]` should be fine.)
223+
///
219224
/// Original mt19937ar.c attribution:
225+
///
220226
/** These real versions are due to Isaku Wada, 2002/01/09 added */
221227
pub fn gen_res53<R: rand::RngCore>(rng: &mut R) -> f64 {
222228
let a = rng.next_u32() >> 5;
@@ -240,8 +246,10 @@ impl rand::RngCore for MT19937 {
240246
}
241247
}
242248

249+
/// Seed for <MT19937 as rand::SeedableRng>
250+
///
243251
/// Very big seed, but this is the size that CPython uses as well
244-
pub struct Seed([u32; N]);
252+
pub struct Seed(pub [u32; N]);
245253
impl Default for Seed {
246254
fn default() -> Self {
247255
Seed([0; N])

0 commit comments

Comments
 (0)