From: Eli Zaretskii Date: Sat, 14 Aug 2021 14:39:38 +0000 (+0300) Subject: Fix 'random' on MS-Windows when integers are wider than 30 bits X-Git-Tag: emacs-28.0.90~1506 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=482049e54277f0a429efdcd660286e9e7b465033;p=emacs.git Fix 'random' on MS-Windows when integers are wider than 30 bits * src/w32.c (random): Provide more random bits for MS-Windows builds with EMACS_INT that is wider than 32 bits. (Bug#32605) --- diff --git a/src/w32.c b/src/w32.c index 968b4bbe489..180c73aa0f0 100644 --- a/src/w32.c +++ b/src/w32.c @@ -2389,8 +2389,13 @@ rand_as183 (void) int random (void) { - /* rand_as183 () gives us 15 random bits...hack together 30 bits. */ + /* rand_as183 () gives us 15 random bits...hack together 30 bits for + Emacs with 32-bit EMACS_INT, and at least 31 bit for wider EMACS_INT. */ +#if EMACS_INT_MAX > INT_MAX + return ((rand_as183 () << 30) | (rand_as183 () << 15) | rand_as183 ()); +#else return ((rand_as183 () << 15) | rand_as183 ()); +#endif } void