Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: random book moves/ random generator

Author: Poschmann

Date: 07:16:38 01/14/00

Go up one level in this thread


On January 13, 2000 at 14:00:10, Christophe Theron wrote:

>On January 13, 2000 at 13:49:41, Robert Hyatt wrote:
>
>>On January 13, 2000 at 12:39:12, Stefan Meyer-Kahlen wrote:
>>
>>>On January 13, 2000 at 11:29:25, Thorsten Greiner wrote:
>>>
>>>>On January 13, 2000 at 11:22:20, Vincent Diepeveen wrote:
>>>>
>>>>>number = rand()%total;
>>>>
>>>>rand() is evil. It uses a linear congruency method like
>>>>
>>>>	new random number = (old random number * constant + constant) % constant
>>>>
>>>>Information in low bits of 'old random number' is lost in this formula. Since
>>>>the number of seconds since 1970 is pretty much constant in lets say January
>>>>2000, the random numbers produced will be quite similar...
>>>>
>>>>Also, never use modulo on the results of rand() - use something like
>>>>
>>>>	rand() / (RAND_MAX / total)
>>>>
>>>>since the low bits of rand() are not as random as the high bits. Or use a real
>>>>random generator - here is a good one: http://www.agner.org/random
>>>>
>>>>Rgds
>>>>	-Thorsten
>>>
>>>
>>>Thorsten is really an expert as far as random numbers are concerned.
>>>I am using his random number generator in Shredder for a couple of years now,
>>>before that I also had similiar problems with rand().
>>>
>>>Stefan
>>
>>
>>Anybody can grab the RNG in Crafty.  It came from the Numerical Recipes book,
>>which came from Knuth's book...  Works well.
>>
>>But that does _not_ solve Vincent's problem.  Any RNG will produce the same
>>sequence of random numbers if it is re-initialized as Vincent is doing.  And
>>this is necessary otherwise we couldn't use these numbers to compute the
>>hash signature to probe the opening book.
>>
>>He needs to re-seed the random number with something that is random itself,
>>such as the millisecond part of the time of day.  Or else use this time of
>>day number to call the RNG repeatedly to skip a random number of random
>>numbers.  And since time of day in milliseconds is very random in the lower
>>order bits, this solves it handily.
>
>
>Be careful with milliseconds on a PC running Windows 9x. Actually the PC timer
>has not changed since prehistory, and it is still producing interrupts at
>18.2Hz. That means that the resolution of time of day under Windows 9x is more
>than 50 milliseconds!
>
>Under Windows NT I remember this is 10ms. Much better, but stil not accurate to
>the millisecond.
>
>I hope this helps.
>
>
>    Christophe

Under Windows you can use the API-function "QueryPerformanceCounter()". The
returned number is incremented approximately every 800 ns. The exact number of
ticks per second you get from the function "QueryPerformanceFrequency()". These
two functions directly use the time counter of every pc.
The functions are also helpful to measure small time intervals without repeating
something in a loop.
Ralf




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.