Dan Honeycutt wrote:Hi all,
Anyone have a preference between the Mersenne twister, KISS, or some other PRNG?
Thanks
Dan H.
I think it's all a matter of taste. You can even hardcode all the numbers that you need. After all, what we need is just to fill an array of zobrist of size NB_COLOR x NB_PIECE x NB_SQUARE, plus a few other special keys (en pasant, castling, and turn of play). All we need is that these numbers are drawn from sufficiently random source, so that recombining them with XOR operation "rarely" leads to collisions.
I think Mersenne Twister, KISS generators, and a ton of other possibilities are all good for the job, so long as they don't have any obvious flaw, and are *properly seeded*.
As a matter of taste, I'd rather use a nice KISS that is elegant and uses only a few lines of code, rather than an obfuscated mersene twister (speed doesn't matter because we only calc a few nubers at program initialization). I use the following KISS generator, attributed to Heinz Van Saanen, that I found in StockFish (though I seed it more simply than SF)
Code: Select all
static inline uint64_t rol(uint64_t x, unsigned k)
{ return (x << k) | (x >> (64 - k)); }
uint64_t rand64()
// 64-bit KISS RNG by Heinz Van Saanen
{
static uint64_t // seeds
a = 0x5bc5cd8748be9fe8,
b = 0x5164ed10aa17c81,
c = 0x105730377a2a0e9c,
d = 0xe6b137acae0d8b76;
const uint64_t e = a - rol(b, 7);
a = b ^ rol(c, 13);
b = c + rol(d, 37);
c = d + e;
return d = e + a;
}
But even an LCG is OK, so long as you seed it properly and that the numbers a and b (such that your LCG is x(t) = a.x(t-1)+b modulo 2^64) verify the proper conditions that give full period to the LCG. Solutions like taking 2 32 bit LCG and combining them work fine, or a 64 bit one and combining 32 bit of one drawing and 32 bit of the next, etc.
The only real question, is how do you know that your zobrist keys are "good enough" ? The only thing I've found is coding a perft with hash tables, and verifying that different zobrist approach give same result on a lot of positions at high depth. I just did it to reassure myself.