Last active
August 29, 2015 14:00
-
-
Save odanado/11238158 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cstdint> | |
#include <cstdio> | |
class MT { | |
uint32_t mt_table[624]; | |
uint32_t mt_count; | |
public: | |
MT(uint32_t s){ | |
mt_table[0] = s; | |
for(int i=1; i<624; i++) { | |
mt_table[i] = ((mt_table[i-1] >> 30) ^ mt_table[i-1]) * 0x6c078965 + i; | |
} | |
mt_count = 0; | |
} | |
uint32_t operator()() { | |
const uint32_t b = (mt_count + 1) % 624; | |
const uint32_t c = (mt_count + 397) % 624; | |
const uint32_t k0 = (mt_table[mt_count] & 0x80000000UL) | (mt_table[b] & 0x7FFFFFFFUL); | |
mt_table[mt_count] = mt_table[c] ^ (k0 >> 1) ^ (0x9908B0DFUL * (k0 & 1)); | |
uint32_t k = mt_table[mt_count]; | |
mt_count = b; | |
k ^= (k >> 11); | |
k ^= (k << 7) & 0x9D2C5680UL; | |
k ^= (k << 15) & 0xEFC60000UL; | |
k ^= (k >> 18); | |
return k; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment