|
@@ -3,18 +3,19 @@
|
|
|
|
|
|
#include "utils/Random.h"
|
|
#include "utils/Random.h"
|
|
|
|
|
|
-Random::Random(int seed) : index(0) {
|
|
|
|
|
|
+Random::Random(Seed seed) : index(0) {
|
|
for(int i = 0; i < N; i++) {
|
|
for(int i = 0; i < N; i++) {
|
|
data[i] = seed;
|
|
data[i] = seed;
|
|
seed = seed * 7 + 31;
|
|
seed = seed * 7 + 31;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-Random::Random() : Random(std::chrono::steady_clock::now().time_since_epoch().count()) {
|
|
|
|
|
|
+Random::Random()
|
|
|
|
+ : Random(std::chrono::steady_clock::now().time_since_epoch().count()) {
|
|
}
|
|
}
|
|
|
|
|
|
void Random::update() {
|
|
void Random::update() {
|
|
- static const int map[2] = {0, -1900031960};
|
|
|
|
|
|
+ static const Seed map[2] = {0, 0x8EBFD028};
|
|
for(int i = 0; i < N - M; i++) {
|
|
for(int i = 0; i < N - M; i++) {
|
|
data[i] = data[i + M] ^ (data[i] >> 1) ^ map[data[i] & 1];
|
|
data[i] = data[i + M] ^ (data[i] >> 1) ^ map[data[i] & 1];
|
|
}
|
|
}
|
|
@@ -28,11 +29,11 @@ int Random::next() {
|
|
if(index >= N) {
|
|
if(index >= N) {
|
|
update();
|
|
update();
|
|
}
|
|
}
|
|
- int r = data[index++];
|
|
|
|
|
|
+ Seed r = data[index++];
|
|
r ^= (r << 7) & 0x2B5B2500;
|
|
r ^= (r << 7) & 0x2B5B2500;
|
|
r ^= (r << 15) & 0xDB8B0000;
|
|
r ^= (r << 15) & 0xDB8B0000;
|
|
r ^= (r >> 16);
|
|
r ^= (r >> 16);
|
|
- return r & static_cast<int>(-1u >> 1);
|
|
|
|
|
|
+ return static_cast<int>(r >> 1);
|
|
}
|
|
}
|
|
|
|
|
|
int Random::next(int min, int inclusiveMax) {
|
|
int Random::next(int min, int inclusiveMax) {
|