X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fmersenne.cpp;h=fee3027fe8f5d47d4c7831e8da2931fbce017e61;hp=2213e4ac9f3abc65c06e8c5e9fed04b65702db7e;hb=72c7595f8ac72c7831ee319b8b0bc46404c5fc27;hpb=bb751d6c890f5c50c642366d601740366cfae8d0 diff --git a/src/mersenne.cpp b/src/mersenne.cpp index 2213e4ac..fee3027f 100644 --- a/src/mersenne.cpp +++ b/src/mersenne.cpp @@ -1,12 +1,12 @@ -/* +/* A C-program for MT19937, with initialization improved 2002/1/26. Coded by Takuji Nishimura and Makoto Matsumoto. - Before using, initialize the state by using init_genrand(seed) + Before using, initialize the state by using init_genrand(seed) or init_by_array(init_key, key_length). Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura, - All rights reserved. + All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions @@ -19,8 +19,8 @@ notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - 3. The names of its contributors may not be used to endorse or promote - products derived from this software without specific prior written + 3. The names of its contributors may not be used to endorse or promote + products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS @@ -42,8 +42,9 @@ */ #include "types.h" +#include "mersenne.h" -/* Period parameters */ +/* Period parameters */ #define N 624 #define M 397 #define MATRIX_A 0x9908b0dfUL /* constant vector a */ @@ -54,12 +55,12 @@ static unsigned long mt[N]; /* the array for the state vector */ static int mti=N+1; /* mti==N+1 means mt[N] is not initialized */ /* initializes mt[N] with a seed */ -void init_genrand(unsigned long s) +static void init_genrand(unsigned long s) { mt[0]= s & 0xffffffffUL; for (mti=1; mti> 30)) + mti); + mt[mti] = + (1812433253UL * (mt[mti-1] ^ (mt[mti-1] >> 30)) + mti); /* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */ /* In the previous versions, MSBs of the seed affect */ /* only MSBs of the array mt[]. */ @@ -73,7 +74,7 @@ void init_genrand(unsigned long s) /* init_key is the array for initializing keys */ /* key_length is its length */ /* slight change for C++, 2004/2/26 */ -void init_by_array(unsigned long init_key[], int key_length) +static void init_by_array(unsigned long init_key[], int key_length) { int i, j, k; init_genrand(19650218UL); @@ -95,7 +96,7 @@ void init_by_array(unsigned long init_key[], int key_length) if (i>=N) { mt[0] = mt[N-1]; i=1; } } - mt[0] = 0x80000000UL; /* MSB is 1; assuring non-zero initial array */ + mt[0] = 0x80000000UL; /* MSB is 1; assuring non-zero initial array */ } /* generates a random number on [0,0xffffffff]-interval */ @@ -123,7 +124,7 @@ uint32_t genrand_int32(void) { mti = 0; } - + y = mt[mti++]; /* Tempering */