File tree Expand file tree Collapse file tree 2 files changed +11
-3
lines changed Expand file tree Collapse file tree 2 files changed +11
-3
lines changed Original file line number Diff line number Diff line change 33// that can be found in the LICENSE file.
44module mt19937
55
6+ import rand.seed
7+
68/*
79C++ functions for MT19937, with initialization improved 2002/2/10.
810 Coded by Takuji Nishimura and Makoto Matsumoto.
@@ -59,12 +61,18 @@ const (
5961// **NOTE**: The RNG is not seeded when instantiated so remember to seed it before use.
6062pub struct MT19937RNG {
6163mut :
62- state []u64 = [] u64 {len: mt 19937 .nn}
64+ state []u64 = get_first_state (seed. time_seed_array ( 2 ))
6365 mti int = mt19937 .nn
6466 bytes_left int
6567 buffer u64
6668}
6769
70+ fn get_first_state (seed_data []u32 ) []u64 {
71+ mut state := []u64 {len: mt19937 .nn}
72+ calculate_state (seed_data, mut state)
73+ return state
74+ }
75+
6876// calculate_state returns a random state array calculated from the `seed_data`.
6977fn calculate_state (seed_data []u32 , mut state []u64 ) []u64 {
7078 lo := u64 (seed_data[0 ])
@@ -83,8 +91,6 @@ pub fn (mut rng MT19937RNG) seed(seed_data []u32) {
8391 eprintln ('mt19937 needs only two 32bit integers as seed: [lower, higher]' )
8492 exit (1 )
8593 }
86- // calculate 2 times because MT19937RNG init didn't call calculate_state.
87- rng.state = calculate_state (seed_data, mut rng.state)
8894 rng.state = calculate_state (seed_data, mut rng.state)
8995 rng.mti = mt19937 .nn
9096 rng.bytes_left = 0
Original file line number Diff line number Diff line change @@ -12,6 +12,8 @@ const (
1212 wyp1 = u64 (0xe7037ed1a0b428db )
1313)
1414
15+ pub const seed_len = 2
16+
1517// WyRandRNG is a RNG based on the WyHash hashing algorithm.
1618pub struct WyRandRNG {
1719mut :
You can’t perform that action at this time.
0 commit comments