/* ISC license. */ #include #include #include uint32_t random_uint32_from (uint32_t n, randomgen_func_ref f) { uint32_t min, x ; if (n < 2) return 0 ; min = -n % n ; for (;;) { char tmp[4] ; (*f)(tmp, 4) ; uint32_unpack_big(tmp, &x) ; if (x >= min) break ; } return x % n ; }