## Search

## Messages

### Subject: Re: random book moves/ random generator

Author: Robert Hyatt

Date: 09:21:36 01/14/00

Go up one level in this thread

On January 14, 2000 at 08:38:11, Vincent Diepeveen 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
>
>Thanks!
>
>I'm checking the link out for some workable C code.
As I mentioned before, look at crafty, utility.c, "Random32()". It is a well-
known and well-tested RNG that produces 32 bit numbers that pass every random
number test with flying colors. I use this and stuff two of them together to
produce 64 bit values for hashing. The code is public-domain, and came from
Knuth's book, later copied in Numerical Recipes.
Several are using this in an effort to come up with a uniform opening book
format that will let several of us swap binary book files without any problems,
since we will be using the same binary format and same random numbers for
hashing.

This page took 0.01 seconds to execute

Last modified: Thu, 07 Jul 11 08:48:38 -0700

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