Moggy stone weighing: Fix case when cap_stone_denom == 0
[pachi/peepo.git] / random.h
blob0722a35ae241ffa41d15b814f01f8828832d61d0
1 #ifndef ZZGO_RANDOM_H
2 #define ZZGO_RANDOM_H
4 #include <stdint.h>
6 #include "util.h"
8 void fast_srandom(unsigned long seed);
9 unsigned long fast_getseed(void);
11 /* Note that only 16bit numbers can be returned. */
12 uint16_t fast_random(unsigned int max);
13 /* Use this one if you want larger numbers. */
14 static uint32_t fast_irandom(unsigned int max);
16 /* Get random number in [0..1] range. */
17 floating_t fast_frandom();
20 static inline uint32_t
21 fast_irandom(unsigned int max)
23 if (max <= 65536)
24 return fast_random(max);
25 int himax = (max - 1) / 65536;
26 uint16_t hi = fast_random(himax + 1);
27 return ((uint32_t)hi << 16) | fast_random(hi < himax ? 65536 : max % 65536);
30 #endif