UCB1AMAF: Major bugfix - do not cycle colors during AMAF update
[pachi/peepo.git] / random.c
blob61f091502678ca8b88add9479cc0a8da8101b692
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_random(unsigned int max)
19 unsigned long hi, lo;
20 lo = 16807 * (pmseed & 0xffff);
21 hi = 16807 * (pmseed >> 16);
22 lo += (hi & 0x7fff) << 16;
23 lo += hi >> 15;
24 pmseed = (lo & 0x7fffffff) + (lo >> 31);
25 return ((pmseed & 0xffff) * max) >> 16;