From f9f90fc3dec73dce21d7a012d31cc9b682d10264 Mon Sep 17 00:00:00 2001 From: emperor06 Date: Tue, 4 Jun 2024 16:42:11 +0200 Subject: [PATCH] ply-utils: Ensure random ints are big enough Using Math.Random() in a theme script practically always returns zero. This is because ply_get_random_number uses mrand48 which, while returning a 64-bit long, restricts the range of its return value to be no more than 32-bit, and so gets improperly normalized. This commit addresses the problem by calling mrand48() twice, once for each 32-bits of the returned value. https://gitlab.freedesktop.org/plymouth/plymouth/-/issues/256 --- src/libply/ply-utils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libply/ply-utils.c b/src/libply/ply-utils.c index 44a93099..0e317b67 100644 --- a/src/libply/ply-utils.c +++ b/src/libply/ply-utils.c @@ -1308,7 +1308,7 @@ ply_get_random_number (long lower_bound, seed_initialized = true; } - offset = mrand48 (); + offset = (mrand48 () << 32) | (mrand48 () & 0xffffffff); offset = labs (offset) % range;