board_try_random_move(): Fix free queue handling in case of permit redirect (Moggy...
[pachi.git] / random.h
blob2c34a990954d197c7438eeeb8e190989fd02bafd
1 #ifndef ZZGO_RANDOM_H
2 #define ZZGO_RANDOM_H
4 #include <stdint.h>
6 void fast_srandom(unsigned long seed);
7 unsigned long fast_getseed(void);
9 /* Note that only 16bit numbers can be returned. */
10 uint16_t fast_random(unsigned int max);
11 /* Use this one if you want larger numbers. */
12 static uint32_t fast_irandom(unsigned int max);
14 /* Get random number in [0..1] range. */
15 float fast_frandom();
18 static inline uint32_t
19 fast_irandom(unsigned int max)
21 if (max <= 65536)
22 return fast_random(max);
23 int himax = max / 65536;
24 uint16_t hi = fast_random(himax + 1);
25 return ((uint32_t)hi << 16) | fast_random(hi < himax ? 65536 : max % 65536);
28 #endif