Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: zobrist key table questions

Author: Tord Romstad

Date: 04:11:11 05/30/04

Go up one level in this thread


On May 30, 2004 at 06:44:55, Uri Blass wrote:

>I have the following function to initialize my random numbers
>
>typedef unsigned __int64 BitBoard;
>
>BitBoard rand64()
>{
>  __int64 r = rand();
>  r ^= (__int64)rand() << 15;
>  r ^= (__int64)rand() << 30;
>  r ^= (__int64)rand() << 45;
>  r ^= (__int64)rand() << 60;
>  return r;
>}
>
>void initializezobarray()
>{
>	//starting zobrist keys
>	char zobnum[128];
>	int fil,i,j;
>	srand(0);
>	for (fil=0;fil<6;fil++)
>		for (i=0;i<2;i++)
>			for (j=0;j<64;j++)
>				zobrist[fil][i][j]=rand64();
>
>
>}
>
>My first question is if I can be sure that I will get the same random numbers in
>every computer(I get the same in my computer but if I do not get the same in
>every computer than I may consider to rewrite it because I plan to use hash keys
>for my book and I do not want to have a problem that the program will not be
>able to use my book in another computer).
>
>I also see that Crafty is using a table of random numbers from a book and does
>not trust rand()

If you use exactly the same executable on different computers, you will probably
get the same random numbers every time.  But if you compile with a different
compiler, you will almost certainly get different random numbers.  In other
words,
you will have to build your book again if you ever change your compiler.

>My second question is if there is an advantage in doing it.

Yes.  The rand() function gives very low-quality random numbers.  If you want
to use a standard C library function, use random() instead.  But it is probably
even better to build your own random number generator, or to just include the
Zobrist keys as a huge constant array in your code.

The random number generator in Crafty works quite well.  Another good one
is the Mersenne Twister:

http://www.math.sci.hiroshima-u.ac.jp/%7Em-mat/MT/emt.html

Tord



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.