1 #ifndef MTTOOLBOX_MERSENNETWISTER64_HPP
2 #define MTTOOLBOX_MERSENNETWISTER64_HPP
66 seed(UINT64_C(19650218));
115 mt =
new uint64_t[N];
145 for (mti = 1; mti < N; mti++) {
147 + UINT64_C(6364136223846793005)
148 * (mt[mti-1] ^ (mt[mti-1] >> 62));
164 void seed(
const std::string& value) {
165 seed_array<char>(value.c_str(),
static_cast<int>(value.size()));
181 void seed(
const uint64_t *value,
int key_length) {
182 seed_array<uint64_t>(value, key_length);
204 seed(UINT64_C(19650218));
207 k = (N > key_length ? N : key_length);
209 mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 62))
210 * UINT64_C(3935559000370003845)))
211 + init_key[j] + (uint64_t)j;
218 if (j >= key_length) {
222 for (k=N-1; k; k--) {
223 mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 62))
224 * UINT64_C(2862933555777941757)))
233 mt[0] = UINT64_C(1) << 63;
264 const uint64_t UPPER_MASK = UINT64_C(0xFFFFFFFF80000000);
265 const uint64_t LOWER_MASK = UINT64_C(0x000000007FFFFFFF);
266 const uint64_t mag01[2] = {0x0UL, UINT64_C(0xB5026F5AA96619E9)};
269 x = (mt[mti] & UPPER_MASK) | (mt[(mti + 1) % N] & LOWER_MASK);
270 mt[mti] = mt[(mti + M) % N] ^ (x >> 1)
271 ^ mag01[(int)(x & UINT64_C(1))];
292 enum {N = 312, M = 156};
295 uint64_t temper(uint64_t y) {
296 y ^= (y >> 29) & UINT64_C(0x5555555555555555);
297 y ^= (y << 17) & UINT64_C(0x71D67FFFEDA60000);
298 y ^= (y << 37) & UINT64_C(0xFFF7EEE000000000);
304 #endif // MTTOOLBOX_MERSENNETWISTER64_HPP
Abstract class of GF(2)-linear pseudo random number generators.