From: emperor06 Date: Tue, 4 Jun 2024 14:42:11 +0000 (+0200) Subject: ply-utils: Ensure random ints are big enough X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f9f90fc3dec73dce21d7a012d31cc9b682d10264;p=thirdparty%2Fplymouth.git 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 --- 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;