Computer Chess Club Archives


Search

Terms

Messages

Subject: random book moves/ random generator

Author: Vincent Diepeveen

Date: 08:22:20 01/13/00


I'm really amazed about next bug Thorsten clearly found:

This is how i do my initialization of random
generator as it is in all examples:

   srand((unsigned int)time(NULL));

Now if we have for example 3 moves A,B,C
with chances that a move gets played:
    A = 30
    B = 30
    C = 30
total = 90

Then obviously i want to play each move the same number of times.

The way in which i pick a move is:

number = rand()%total;

   A ==>  0..29
   B ==> 30..59
   C ==> 60..89

Now if i get more or less random numbers then i would expect that
'number' falls in 1/3 of the times between 0..29, at 1/3 of the times
between 30..59 and 1/3 of the times at 60..89

However if i start diep THEN THIS DOESN'T HAPPEN, as Thorsten
already figured out himself.

Sure it sometimes picks a different move, but it favours a certain move
a lot more than other moves.

This happens ONLY when i restart the program each time. I don't restart
within a second of course. Srand doesn't get initialized at the same
number each time.

If i just type inside the program 'newgame' and see what it has done now,
then this problem happens a lot less. It seems working then. Problem are
there clearly the first few numbers that i get from rand after initializing
srand with the time since 1970.

Questions

 a) is this problem known?
 b) what causes it?
 c) how to fix it?






This page took 0.72 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.