Predictable Randomness

One GNU Chess source file I didn’t port to Java was the random number generator, and that turned out to be a problem for processing the binary opening book files.

The board position hash codes are 64-bit numbers created by xor’ing a set of hash codes that come from the random number generator. These hash codes are written to the binary book file, so in order to read a binary book file, you have to get the exact same sequence of “random” numbers from your random number generator. So I ported over the random number algorithm and was then able to read the binary book files which allows the program to play moves from the opening book.

I also got PGN file reading working, so I don’t know of any remaining functional issues (except for the i/o handling, especially control-C, which I may just ignore).

I tried the program on the 300 “Win at Chess” problems. The Java version got 278 correct, and the C version got 284 correct. Both used 5 seconds per move on my Mac G5.

2 Responses to “Predictable Randomness”

  1. Anli says:

    Interesting. Do you plan on publishing any of the stuff? How did C’s PRNG work?

  2. xan says:

    Yes, I will probably just make a zip archive rather than anything fancy once I figure out a name. The PRNG is right out of Knuth.

Leave a Reply