[computer-go] C++ random numbers
Darren Cook
darren at dcook.org
Tue Aug 8 16:27:27 PDT 2006
> Okay, next question: how do I generate a random 64-bit unsigned integer?
Here is the code I have in my zobrist class:
srand48(seed);
unsigned int v1,v2;
for(...){
v1=static_cast<unsigned int>(mrand48());
v2=static_cast<unsigned int>(mrand48());
//Combine v1 and v2 into a 64 bit int
...
}
I had this comment in the code:
mrand48() returns a number between -2^31 and +2^31. This
is then cast to an unsigned int. The alternatives
don't seem to give the full 32 bit number.
I couldn't understand what to do with the Boost.Random functions.
mrand48 may be linux-only.
If you want to try the boost functions:
http://www.boost.org/libs/random/index.html
Darren
P.S. In my zobrist code I actually store as 2 sets of 32-bit numbers
rather than a 64-bit int. I have the following comment, and I'm
wondering what other people think about it (there was a big discussion
about generating zobrist numbers a year or so ago, but I didn't fully
understand it!):
The checks I do for repeated numbers are actually stricter than if using
a 64 bit integer, as it requires both high and low halves to
be unique. I suspect this is good (less chance of two different
positions having the same hash code), but otherwise it makes no difference.
If it was good then it'd be worth generating 16 bit numbers and check
their uniqueness, then combining them to make the 32 bit numbers.
More information about the computer-go
mailing list