Permalink
Browse files

Allow to pass a 'seed' to RKISS

This somewhat simplifies the code.

Suggested by Lucas Braesch.

No functional change.
  • Loading branch information...
1 parent 009a0f8 commit 896420b1661d3ec1247487dbaf73e05546a1d625 @mcostalba committed Dec 31, 2012
Showing with 4 additions and 10 deletions.
  1. +1 −5 src/book.cpp
  2. +3 −5 src/rkiss.h
View
@@ -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
@@ -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()); }
};

2 comments on commit 896420b

@lucasart
Contributor

Here's what I had in mind:

RKISS(uint64_t seed = 0xbbf4d93b7200e858)
// RKISS generator by Bob Jenkins. Seed values tested by Heinz Van Saanen
{
a = 0x46dd577ff603b540;
b = 0xc4077bddfacf987b;
c = seed;
d = 0xd3e075cfd449bb1e;
}

Advantage:

  • drop the loop, use an uint64_t seed (with std::clock you can surely find some good way to make large seeds, like number of clock ticks since "epoch" or whatever)
  • more than 10,000 possible starting states for Polyglot book selection
@mcostalba
Owner
Please sign in to comment.