… | |
… | |
22 | |
22 | |
23 | #ifndef RNG_H__ |
23 | #ifndef RNG_H__ |
24 | #define RNG_H__ |
24 | #define RNG_H__ |
25 | |
25 | |
26 | #include <compiler.h> |
26 | #include <compiler.h> |
|
|
27 | |
|
|
28 | typedef uint32_t seed_t; // overkill |
27 | |
29 | |
28 | // P. L'Ecuyer, “Maximally Equidistributed Combined Tausworthe Generators”, Mathematics of Computation, 65, 213 (1996), 203–213. |
30 | // P. L'Ecuyer, “Maximally Equidistributed Combined Tausworthe Generators”, Mathematics of Computation, 65, 213 (1996), 203–213. |
29 | // http://www.iro.umontreal.ca/~lecuyer/myftp/papers/tausme.ps |
31 | // http://www.iro.umontreal.ca/~lecuyer/myftp/papers/tausme.ps |
30 | // http://www.iro.umontreal.ca/~lecuyer/myftp/papers/tausme2.ps |
32 | // http://www.iro.umontreal.ca/~lecuyer/myftp/papers/tausme2.ps |
31 | struct tausworthe_rng |
33 | struct tausworthe_rng |
… | |
… | |
105 | } |
107 | } |
106 | while (i); |
108 | while (i); |
107 | } |
109 | } |
108 | |
110 | |
109 | // actually should subclass to gfsr32... :) |
111 | // actually should subclass to gfsr32... :) |
110 | void seed (uint32_t seed) |
112 | void seed (seed_t seed) |
111 | { |
113 | { |
112 | xorshift_rng rng; |
114 | xorshift_rng rng; |
113 | |
115 | |
114 | rng.seed (seed); |
116 | rng.seed (seed); |
115 | this->seed_rng (rng); |
117 | this->seed_rng (rng); |
… | |
… | |
155 | { |
157 | { |
156 | random_number_generator () |
158 | random_number_generator () |
157 | { |
159 | { |
158 | } |
160 | } |
159 | |
161 | |
160 | random_number_generator (uint32_t seed) |
162 | random_number_generator (seed_t seed) |
161 | { |
163 | { |
162 | this->seed (seed); |
164 | this->seed (seed); |
163 | } |
165 | } |
164 | |
166 | |
165 | // uniform distribution, [0 .. num - 1] |
167 | // uniform distribution, [0 .. num - 1] |