Function mt19937::gen_res53 [−][src]
pub fn gen_res53<R: RngCore>(rng: &mut R) -> f64
generates a random number on [0,1) with 53-bit resolution
This generates a float with the same algorithm that CPython uses; calling
it with an MT19937
with a given seed returns the same as it would in CPython.
e.g.:
let mut m = mt19937::MT19937::new_with_slice_seed(&[12345]); let expected: f64 = 0.416619872545341163316834354191087186336517333984375; assert_eq!(mt19937::gen_res53(&mut m), expected);
and in Python:
import random
random.seed(12345)
expected = 0.416619872545341163316834354191087186336517333984375
assert random.random() == expected
(note that CPython converts ints to slices by taking the native endian ordering
of the underlying “BigInt” implementation, but for seeds < u32::max_value(),
just &[seed]
should be fine.)
Original mt19937ar.c attribution:
These real versions are due to Isaku Wada, 2002/01/09 added