From: Tony Finch Date: Thu, 14 Apr 2022 18:06:02 +0000 (+0100) Subject: Clean up isc_random X-Git-Tag: v9.19.1~56^2~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=254d2abafb45292b2397fe7f086f0f9d0f44cbf9;p=thirdparty%2Fbind9.git Clean up isc_random Remove redundant comments and avoid implicit casts. --- diff --git a/lib/isc/random.c b/lib/isc/random.c index 06baaa1aca9..842f4e4fe3f 100644 --- a/lib/isc/random.c +++ b/lib/isc/random.c @@ -44,22 +44,6 @@ #include "entropy_private.h" -/* - * The specific implementation for PRNG is included as a C file - * that has to provide a static variable named seed, and a function - * uint32_t next(void) that provides next random number. - * - * The implementation must be thread-safe. - */ - -/* - * Two contestants have been considered: the xoroshiro family of the - * functions by Villa&Blackman, and PCG by O'Neill. After - * consideration, the xoshiro128starstar function has been chosen as - * the uint32_t random number provider because it is very fast and has - * good enough properties for our usage pattern. - */ - /* * Written in 2018 by David Blackman and Sebastiano Vigna (vigna@acm.org) * @@ -76,11 +60,9 @@ * It has excellent (sub-ns) speed, a state size (128 bits) that is large * enough for mild parallelism, and it passes all tests we are aware of. * - * For generating just single-precision (i.e., 32-bit) floating-point - * numbers, xoshiro128+ is even faster. - * * The state must be seeded so that it is not everywhere zero. */ + static thread_local uint32_t seed[4] = { 0 }; static uint32_t @@ -128,14 +110,14 @@ uint8_t isc_random8(void) { RUNTIME_CHECK(isc_once_do(&isc_random_once, isc_random_initialize) == ISC_R_SUCCESS); - return (next() & 0xff); + return ((uint8_t)next()); } uint16_t isc_random16(void) { RUNTIME_CHECK(isc_once_do(&isc_random_once, isc_random_initialize) == ISC_R_SUCCESS); - return (next() & 0xffff); + return ((uint16_t)next()); } uint32_t