Author: James Swafford
Date: 08:11:19 04/13/99
Go up one level in this thread
On April 13, 1999 at 10:56:04, Gareth McCaughan wrote: >[James Swafford] >>> My opening book relies on a random number generation to >>> choose among book entries. Windows random( ) function >>> leaves a lot to be desired, even when reseeded using the >>> system timer before each call. >... >[Bruce Moreland] >> Don't re-seed using the system timer before each call. The resolution on the >> system timer isn't that great, you can conceivably get the same seed several >> times in a row, which will get you the same random number back. >> >> Maybe this is your problem. > >I think it's very likely to be. > >There are plenty of subtle problems computers' random number generators >can have, but I really can't imagine any of them being serious enough >to be a problem for the purpose of selecting book moves. With one possible >exception: if you need a smallish random number, try to avoid taking just >the low bits of the result of calling |rand| or whatever. Some RNGs have >very non-random low bits. In particular, if you want a random number in >[0,n) it's *not* a good idea to write |rand()%n|. Something more along the >lines of |rand()/((RAND_MAX+n-1)/n)| is better. (Errrrm, be careful with >that suggestion: think about signed integer overflow. You probably need >some casts in there. Isn't C horrible?) rand() % n is exactly what I've been doing. :-) I'll try Bruce's suggestion (not reseeding). If that doesn't work, I'll try your algorithm. Thanks for the replies. -- James
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.