Computer Chess Club Archives


Search

Terms

Messages

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

Author: Amir Ban

Date: 07:36:58 10/18/98

Go up one level in this thread


On October 18, 1998 at 10:15:54, Ed Schröder wrote:

>>>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<LENGTGH; 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.
>
>>>- Ed -
>
>>>From the definition of LENGTH I guess these are piece-square tables you are
>>generating.
>
>Yes.
>
>>I do the same, but I generate 48-bit numbers (actually only 45-bit, because I
>>don't bother completing the MSbit), not 32-bit as you do. I think it's
>>generally acknowledged that 32-bit is not enough ?
>
>Let me give an example with a 32-bit hash-key:
>
>Total positions searched    : 1,386,498
>Hash errors                 :       453
>
>These 453 errors are discovered checking the positions when a hash hit occurs
>so they are 100% examples the hash algorithm fails. I find this number quite
>(much too) high.
>
>When I increase the number of bits to 40 or 48 the number of errors drops to
>(say) 200 / 150. Still much to high IMO.
>
>So my suspect goes to random generator.
>
>- Ed -
>
>
>>Amir

This sounds wrong indeed.

Try this rand function (this is the Borland implementation). I use srand(0),
though I don't believe it matters.


#define MULTIPLIER      0x015a4e35L
#define INCREMENT       1

static  long    Seed = 1;

void __cdecl srand(unsigned seed)
{
  Seed = seed;
}


int __cdecl rand(void)
{
  Seed = MULTIPLIER * Seed + INCREMENT;
  return((int)(Seed >> 16) & 0x7fff);
}


Amir



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.