17 #define IMPLEMENT_RAND_UNSIGNED(type, maxval, limit, fill_stmt) \
21 tor_assert((limit) > 0); \
26 cutoff = (maxval) - ((maxval)%(limit)); \
30 return val % (limit); \
114 #define UINT_MAX_AS_DOUBLE 4294967296.0
115 #elif SIZEOF_INT == 8
116 #define UINT_MAX_AS_DOUBLE 1.8446744073709552e+19
118 #error SIZEOF_INT is neither 4 nor 8
132 return ((
double)u) / UINT_MAX_AS_DOUBLE;
174 uint64_t min, uint64_t max)
177 if (BUG(min >= max)) {
192 return ((
double)u) / UINT_MAX_AS_DOUBLE;
void crypto_rand(char *to, size_t n)
Common functions for using (pseudo-)random number generators.
void crypto_fast_rng_getbytes(crypto_fast_rng_t *rng, uint8_t *out, size_t n)
uint64_t crypto_fast_rng_uint64_range(crypto_fast_rng_t *rng, uint64_t min, uint64_t max)
#define IMPLEMENT_RAND_UNSIGNED(type, maxval, limit, fill_stmt)
time_t crypto_rand_time_range(time_t min, time_t max)
uint64_t crypto_rand_uint64_range(uint64_t min, uint64_t max)
double crypto_fast_rng_get_double(crypto_fast_rng_t *rng)
uint32_t crypto_fast_rng_get_u32(crypto_fast_rng_t *rng)
uint64_t crypto_fast_rng_get_uint64(crypto_fast_rng_t *rng, uint64_t limit)
unsigned crypto_fast_rng_get_uint(crypto_fast_rng_t *rng, unsigned limit)
unsigned crypto_rand_uint(unsigned limit)
double crypto_rand_double(void)
int crypto_rand_int_range(unsigned int min, unsigned int max)
uint64_t crypto_rand_uint64(uint64_t max)
int crypto_rand_int(unsigned int max)
Macros to manage assertions, fatal and non-fatal.