Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Source code for very good 64 bits generator for hashing

Author: Vincent Diepeveen

Date: 18:01:26 10/28/03

Go up one level in this thread


On October 28, 2003 at 20:58:57, Vincent Diepeveen wrote:

2 additional defines:

#if UNIX
  #include <time.h>
  #define FORCEINLINE       __inline
  #define BITBOARD          unsigned long long
#else
  #define FORCEINLINE       __forceinline
  /* in WINDOWS we also want to be 64 bits: */
  #define BITBOARD          unsigned _int64
#endif

>On October 28, 2003 at 16:16:53, Dieter Buerssner wrote:
>
>All what is needed is that there is no multilineair connection between the
>outputted numbers, of course assuming a reasonable cycle length.
>
>Even a 64 bits rewrite of the very fast ranrot i did and spreaded around
>is doing fine here:
>
>#define KK  17
>#define JJ  10
>#define R1   5
>#define R2   3
>
>BITBOARD randbuffer[KK+3] = { /* history buffer filled with some random numbers
>*/
>
>0x92930cb295f24dab,0x0d2f2c860b685215,0x4ef7b8f8e76ccae7,0x03519154af3ec239,0x195e36fe715fad23,
>
>0x86f2729c24a590ad,0x9ff2414a69e4b5ef,0x631205a6bf456141,0x6de386f196bc1b7b,0x5db2d651a7bdf825,
>
>0x0d2f2c86c1de75b7,0x5f72ed908858a9c9,0xfb2629812da87693,0xf3088fedb657f9dd,0x00d47d10ffdc8a9f,
>
>0xd9e323088121da71,0x801600328b823ecb,0x93c300e4885d05f5,0x096d1f3b4e20cd47,0x43d64ed75a9ad5d9
>
>/*0xa05a7755512c0c03,0x960880d9ea857ccd,0x7d9c520a4cc1d30f,0x73b1eb7d8891a8a1,0x116e3fc3a6b7aadb*/
>};
>int r_p1, r_p2;          /* indexes into history buffer */
>
> /******************************************************** AgF 1999-03-03 *
> *  Random Number generator 'RANROT' type B                               *
> *  by Agner Fog                                                          *
> *  speeded up a number of times by Vincent Diepeveen (2003)              *
> *                                                                        *
> *  This is a lagged-Fibonacci type of random number generator with       *
> *  rotation of bits.  The algorithm is:                                  *
> *  X[n] = ((X[n-j] rotl r1) + (X[n-k] rotl r2)) modulo 2^b               *
> *                                                                        *
> *  The last k values of X are stored in a circular buffer named          *
> *  randbuffer.                                                           *
> *                                                                        *
> *  This version works with any integer size: 16, 32, 64 bits etc.        *
> *  The integers must be unsigned. The resolution depends on the integer  *
> *  size.                                                                 *
> *                                                                        *
> *  Note that the function RanrotAInit must be called before the first    *
> *  call to RanrotA or iRanrotA                                           *
> *                                                                        *
> *  The theory of the RANROT type of generators is described at           *
> *  www.agner.org/random/ranrot.htm                                       *
> *                                                                        *
> *************************************************************************/
>
>FORCEINLINE BITBOARD rotl(BITBOARD x,int r) {return(x<<r)|(x>>(64-r));}
>
>/* returns a random number of 64 bits unsigned */
>FORCEINLINE BITBOARD RanrotA(void) {
>  /* generate next random number */
>  BITBOARD x = randbuffer[r_p1] = rotl(randbuffer[r_p2],R1) +
>rotl(randbuffer[r_p1], R2);
>  /* rotate list pointers */
>  if( --r_p1 < 0)
>    r_p1 = KK - 1;
>  if( --r_p2 < 0 )
>    r_p2 = KK - 1;
>  return x;
>}
>
>/* this function initializes the random number generator.      */
>void RanrotAInit(void) {
>  int i;
>
>  /* one can fill the randbuffer here with possible other values here */
>  randbuffer[0] = 0x92930cb295f24000 | (BITBOARD)ProcessNumber;
>  randbuffer[1] = 0x0d2f2c860b000215 | ((BITBOARD)ProcessNumber<<12);
>
>  /* initialize pointers to circular buffer */
>  r_p1 = 0;
>  r_p2 = JJ;
>
>  /* randomization init */
>  for( i = 0; i < 3000; i++ )
>    (void)RanrotA();
>}
>
>
>>On October 28, 2003 at 15:46:27, Dan Andersson wrote:
>>
>>> There is one supposedly 'very' secure and simple random generator that I like
>>>because of its simplicity and randomness. The only assumption made is that
>>>factoring large integers is 'hard'. The Blum Blum Shub:
>>>    Xn+1 = (Xn)2 mod M where M is a product of two large primes. The O(log log
>>>M) least significant bits are random. You can also use relatively low values for
>>>M and use the parity of Xn as output for one bit at a time if large values are
>>>unworkable.
>>
>>I am not too convinced, yet. Can you show a sample implementation here
>>(preferably one, that does have M < 2**64 - I am not interested in cryptographic
>>use, just like to test the randomness of the output).
>>I guess, I can implement it myself easily, when you can suggest a suitable M.
>>Perhaps you would also know the cycle-length. The cycle length clearly <= M. So,
>>I fear, it is possible, that it may fail known statistical tests on the
>>randomness for even rather large values of M. For intermediate values (say
>>around 2**63) one might already get a "feeling" about its behaviour.
>>
>>
>>> It is not fast by any means ;)
>>
>>It should be more than fast enough for chess engines. It might be fast enough
>>for some serious simulations.
>>
>>Regards,
>>Dieter



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.