/* ISC license. */ #include #ifdef SKALIBS_HASARC4RANDOM #include #include #include #include uint32_t random_uint32 (uint32_t n) { return arc4random_uniform(n) ; } #else #include #include #include uint32_t random_uint32 (uint32_t n) { uint32_t min, x ; if (n < 2) return 0 ; min = -n % n ; for (;;) { char tmp[4] ; random_string(tmp, 4) ; uint32_unpack(tmp, &x) ; if (x >= min) break ; } return x % n ; } #endif