1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-05-01 01:03:09 +00:00

Allow to pass a 'seed' to RKISS

This somewhat simplifies the code.

Suggested by Lucas Braesch.

No functional change.
This commit is contained in:
Marco Costalba 2012-12-31 11:57:49 +01:00
parent 009a0f88e0
commit 896420b166
2 changed files with 4 additions and 10 deletions

View file

@ -348,11 +348,7 @@ namespace {
} // namespace
PolyglotBook::PolyglotBook() {
for (int i = Time::now() % 10000; i > 0; i--)
RKiss.rand<unsigned>(); // Make random number generation less deterministic
}
PolyglotBook::PolyglotBook() : RKiss(Time::now() % 10000) {}
PolyglotBook::~PolyglotBook() { if (is_open()) close(); }

View file

@ -61,17 +61,15 @@ class RKISS {
return s.d = e + s.a;
}
// Init seed and scramble a few rounds
void raninit() {
public:
RKISS(int seed = 73) {
s.a = 0xf1ea5eed;
s.b = s.c = s.d = 0xd4e12c77;
for (int i = 0; i < 73; i++)
for (int i = 0; i < seed; i++) // Scramble a few rounds
rand64();
}
public:
RKISS() { raninit(); }
template<typename T> T rand() { return T(rand64()); }
};