Author: Stuart Cracraft
Date: 17:18:02 07/11/04
Go up one level in this thread
On July 11, 2004 at 19:29:50, Dieter Buerssner wrote: >On July 11, 2004 at 19:13:53, Stuart Cracraft wrote: > >>I was using something like that but picked up this from Knuth >>by way of GNU & Crafty (and, I suspect, Bob Hyatt)... The question is >>will this suffice for the new 64-bit machines becoming more commonplace >>amongst computer chess programs... > >It will most probably run on all modern machines. To make it really portable (to >old machines, that don't have 32-bit ints, or new machines that may have longer >than 32-bit ints, see my suggestions in the code) > >>unsigned int Rand32 (void) >unsigned long Rand32 (void) > >>/*************************************************************************** >>* >> * >> * A 32 bit random number generator. An implementation in C of the >> * algorithm given by Knuth, the art of computer programming, vol. 2, >> * pp. 26-27. We use e=32, so we have to evaluate y(n) = y(n-24) + y(n-55) >> * mod 2^32, which is implicitly done by unsigned arithmetic. >> * >> >>***************************************************************************/ >>{ >>/* >> * Random numbers from Mathematica 2.0 >> * SeedRandom = 1; >> * Table[Random[Integer, {0, 2^32 - 1}] >> */ >> static unsigned int x[55] = > >static unsigned long x[55] = > > >> { >> 1410651636UL, >> 3012776752UL, >> 3497475623UL, >> 2892145026UL, >> 1571949714UL, >> 3253082284UL, >> 3489895018UL, >> 387949491UL, >> 2597396737UL, >> 1981903553UL, >> 3160251843UL, >> 129444464UL, >> 1851443344UL, >> 4156445905UL, >> 224604922UL, >> 1455067070UL, >> 3953493484UL, >> 1460937157UL, >> 2528362617UL, >> 317430674UL, >> 3229354360UL, >> 117491133UL, >> 832845075UL, >> 1961600170UL, >> 1321557429UL, >> 747750121UL, >> 545747446UL, >> 810476036UL, >> 503334515UL, >> 4088144633UL, >> 2824216555UL, >> 3738252341UL, >> 3493754131UL, >> 3672533954UL, >> 29494241UL, >> 1180928407UL, >> 4213624418UL, >> 33062851UL, >> 3221315737UL, >> 1145213552UL, >> 2957984897UL, >> 4078668503UL, >> 2262661702UL, >> 65478801UL, >> 2527208841UL, >> 1960622036UL, >> 315685891UL, >> 1196037864UL, >> 804614524UL, >> 1421733266UL, >> 2017105031UL, >> 3882325900UL, >> 810735053UL, >> 384606609UL, >> 2393861397UL >> }; >> static int init = true; >> static unsigned int y[55]; > > static unsigned long y[55]; > >> static int j, k; >> unsigned int ul; > >unsigned long ul; > >> if (init) >> { >> int i; >> init = false; >> for (i = 0; i < 55; i++) >> y[i] = x[i]; >> j = 24 - 1; >> k = 55 - 1; >> } >> ul = (y[k] += y[j]); > > y[k] += y[j]; > ul = (y[k] &= 0xffffffff); > > >> if (--j < 0) j = 55 - 1; >> if (--k < 0) k = 55 - 1; >> return (ul); >>} > >Above changes assume, that efficiency is no issue (it ain't in chess engines). >If it is, one might want to use environment specific types, instead of unsigned >long. Also doing something different about the init and the "local" y table. > >Don't use this for serious simulations, without really knowing what you are >doing. Above PRNG (an additive lagged Fibonacci PRNG, from my memory Knuth >suggested subtraction instead of addition for this. But it won't really matter.) >has very serious flaws, and fails some simple tests for randomness. For Zorbrist >hashing there will be no problem. > >Regards, >Dieter Good point. No true randomness, just Zobrist-capable... I guess one might want a similar randomness for the program to pick amongst equally similar moves +- a few evaluation points. No nuclear simulations here. Stuart
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.