From: Willy Tarreau Date: Mon, 25 May 2026 18:43:38 +0000 (+0200) Subject: BUG/MINOR: haterm: fix the random suffix multiplication X-Git-Tag: v3.4-dev14~43 X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=e8c9aabd62372fc2caa74b8009b22bbf784777ef;p=thirdparty%2Fhaproxy.git BUG/MINOR: haterm: fix the random suffix multiplication Passing a size or anything with suffix "r" is supposed to apply a random factor form 0 to 1. However due to the replacement of random() with ha_random64(), all 64 bits are random before the divide, so the end result is a random 32-bit value. In addition, ha_random64() is slow since shared between threads. Let's use statistical_prng() which is designed for this purpose and is much cheaper. No backport is needed, this is only in 3.4. --- diff --git a/src/haterm.c b/src/haterm.c index f7d9ffae5..f1b227214 100644 --- a/src/haterm.c +++ b/src/haterm.c @@ -788,7 +788,7 @@ static void hstream_parse_uri(struct ist uri, struct hstream *hs) } while (*next); if (use_rand) - result = ((long long)ha_random64() * result) / ((long long)RAND_MAX + 1); + result = ((long long)statistical_prng() * result) / 0xFFFFFFFFU; switch (*arg) { case 's':