MINOR: backend: use a single call to ha_random32() for the random LB algo
authorWilly Tarreau <w@1wt.eu>
Sun, 8 Mar 2020 16:31:39 +0000 (17:31 +0100)
committerWilly Tarreau <w@1wt.eu>
Wed, 11 Mar 2020 06:35:16 +0000 (07:35 +0100)
For the random LB algorithm we need a random 32-bit hashing key that used
to be made of two calls to random(). Now we can simply perform a single
call to ha_random32() and get rid of the useless operations.

(cherry picked from commit b9f54c55929eddb6446f8d5c983fb8f1008eb0c6)
Signed-off-by: Willy Tarreau <w@1wt.eu>

src/backend.c

index e7167d1..6e50a5c 100644 (file)
@@ -539,8 +539,7 @@ static struct server *get_server_rnd(struct stream *s, const struct server *avoi
        curr = NULL;
        do {
                prev = curr;
-               /* ensure all 32 bits are covered as long as RAND_MAX >= 65535 */
-               hash = ((uint64_t)ha_random() * ((uint64_t)RAND_MAX + 1)) ^ ha_random();
+               hash = ha_random32();
                curr = chash_get_server_hash(px, hash, avoid);
                if (!curr)
                        break;