|
@@ -1,7 +1,11 @@
|
|
|
#include "core/utils/Random.hpp"
|
|
|
|
|
|
-Core::Random::Random(Seed seed) : index(0) {
|
|
|
- for(int i = 0; i < N; i++) {
|
|
|
+#include <stdio.h>
|
|
|
+
|
|
|
+constexpr static int M = 7;
|
|
|
+
|
|
|
+Core::Random::Random(Seed seed) : data(), index(0) {
|
|
|
+ for(int i = 0; i < data.getLength(); i++) {
|
|
|
data[i] = seed;
|
|
|
seed = seed * 7 + 31;
|
|
|
}
|
|
@@ -9,17 +13,18 @@ Core::Random::Random(Seed seed) : index(0) {
|
|
|
|
|
|
void Core::Random::update() {
|
|
|
static const Seed map[2] = {0, 0x8EBFD028};
|
|
|
- for(int i = 0; i < N - M; i++) {
|
|
|
+ for(int i = 0; i < data.getLength() - M; i++) {
|
|
|
data[i] = data[i + M] ^ (data[i] >> 1) ^ map[data[i] & 1];
|
|
|
}
|
|
|
- for(int i = N - M; i < N; i++) {
|
|
|
- data[i] = data[i + (M - N)] ^ (data[i] >> 1) ^ map[data[i] & 1];
|
|
|
+ for(int i = data.getLength() - M; i < data.getLength(); i++) {
|
|
|
+ data[i] = data[i + (M - data.getLength())] ^ (data[i] >> 1) ^
|
|
|
+ map[data[i] & 1];
|
|
|
}
|
|
|
index = 0;
|
|
|
}
|
|
|
|
|
|
int Core::Random::next() {
|
|
|
- if(index >= N) {
|
|
|
+ if(index >= data.getLength()) {
|
|
|
update();
|
|
|
}
|
|
|
Seed r = data[index++];
|