From: Willy Tarreau Date: Sat, 17 Apr 2021 13:49:34 +0000 (+0200) Subject: MINOR: tools: add statistical_prng_range() to get a random number over a range X-Git-Tag: v2.4-dev17~68 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=84ebfabf7;p=thirdparty%2Fhaproxy.git MINOR: tools: add statistical_prng_range() to get a random number over a range This is simply a multiply and shift from statistical_prng() but it's made easily accessible. --- diff --git a/include/haproxy/tools.h b/include/haproxy/tools.h index 3121fea51a..e09e17e644 100644 --- a/include/haproxy/tools.h +++ b/include/haproxy/tools.h @@ -1073,6 +1073,14 @@ static inline unsigned int statistical_prng() return statistical_prng_state = x; } +/* returns a random number between 0 and - 1 that is evenly distributed + * over the range. + */ +static inline uint statistical_prng_range(uint range) +{ + return mul32hi(statistical_prng(), range); +} + /* Update array with the character transition to . If * is zero, it's assumed that is the first character. If is zero * its assumed to mark the end. Both may be zero. is a 1024-entries array