Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: How to create a set of random integers for hashing?

Author: Peter McKenzie

Date: 13:29:36 10/18/98

Go up one level in this thread


>Since ages I use the following formula for creating a set of random
>integers for hashing at program start:
>
>#define LENGTH 64*12
>
>int random [LENGTH];
>
>int a,b,c,d,x;
>
>srand(9);                    // initialize prime number
>
>for (x=0; x { a=rand(); b=rand(); if (b & 1) a=a | 0x8000;
>   c=rand(); d=rand(); if (d & 1) c=c | 0x8000;
>   random[x]=(a<<16)+c;
> }
>
>I wonder how good such a system is and how others do it.

I definitely wouldn't trust rand(), isn't it only guaranteed by the C standard
to have a cyle of at least 4096 ?
Also, its implementation differs between compilers and platforms which is a pain
if you have a multi platform program (its always nice to match node counts for a
fixed depth search to make sure the program is working right on a new platform).

My random number generator is based on the Java random number generator, which I
believe is based on something in Knuth and therefore probably quite good (I hope
:).

My implementation is as follows:
I wrote a simple java program to dump several thousand random numbers to a text
file, in a format that can be included into a C source file to initialise an
array.  So my actual random number function just grabs the next number from this
array (and cycles back to the start when reaching the end).

cheers,
Peter



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.