play_random_game(), uct_playout(): Do not consider the 0th move actually a pass
[pachi/json.git] / random.c
blob7fcbf4a97456e477dd9481d164a4a0cc023d2454
1 #include <stdio.h>
3 #include "random.h"
6 /* Simple Park-Miller */
8 static __thread unsigned long pmseed = 29264;
10 void
11 fast_srandom(unsigned long seed_)
13 pmseed = seed_;
16 unsigned long
17 fast_getseed(void)
19 return pmseed;
22 unsigned long
23 fast_random(unsigned int max)
25 unsigned long hi, lo;
26 lo = 16807 * (pmseed & 0xffff);
27 hi = 16807 * (pmseed >> 16);
28 lo += (hi & 0x7fff) << 16;
29 lo += hi >> 15;
30 pmseed = (lo & 0x7fffffff) + (lo >> 31);
31 return ((pmseed & 0xffff) * max) >> 16;