8 void srand_safe(unsigned int seed) {
13 // RAND_MAX is guaranteed to be at least 32767
14 // but math with rand() is annoying.
15 // Here's a canned solution from
16 // http://www.azillionmonkeys.com/qed/random.html
17 // which gives uniform numbers in [0, r)
19 #define RS_SCALE (1.0 / (1.0 + RAND_MAX))
24 d = (((random() * RS_SCALE) + random()) * RS_SCALE + random()) * RS_SCALE;
25 } while (d >= 1); /* Round off */
29 #define irand(x) ((unsigned int) ((x) * drand()))
31 // use this to construct a 32-bit thread-safe RNG
32 #define RAND32 ((uint32_t)irand(1ul<<32))
33 uint32_t rand32_safe() {