From: Andy Moreton <andrewjmoreton@gmail.com>
To: 32605@debbugs.gnu.org
Subject: bug#32605: [w64] (random) never returns negative
Date: Sat, 14 Aug 2021 14:40:35 +0100 [thread overview]
Message-ID: <86a6lkywj0.fsf@gmail.com> (raw)
In-Reply-To: <855zzpf86u.fsf@gmail.com>
On Sat 14 Aug 2021, Eli Zaretskii wrote:
>> From: Andy Moreton <andrewjmoreton@gmail.com>
>> Date: Sat, 14 Aug 2021 13:10:08 +0100
>>
>> > Why not keep the 30 bits we produce today on 32-bit builds?
>>
>> For 32bit builds (FIXNUM_BITS is 30), either:
>>
>> a) define RAND_BITS to 30, 'random' calls 'rand_as183' twice.
>> 'get_random' needs 1 call to 'random' (total 2 calls of 'rand_as183').
>>
>> b) define RAND_BITS to 15, 'random' calls 'rand_as183' once.
>> 'get_random' needs 2 calls to 'random' (total 2 calls of 'rand_as183').
>>
>> For 64bit builds (FIXNUM_BITS is 62), either:
>>
>> a) define RAND_BITS to 30, 'random' calls 'rand_as183' twice.
>> 'get_random' needs 3 calls to 'random' (total 6 calls of 'rand_as183').
>>
>> b) define RAND_BITS to 15, 'random' calls 'rand_as183' once.
>> 'get_random' needs 4 calls to 'random' (total 4 calls of 'rand_as183').
>>
>> On 32bit builds both options are roughly equivalent.
>> On 64bit builds option (b) is better as option (a) does unnecessary work.
>
> The above assumes we will never call 'random' except via 'get_random'.
> Is that something we want to bet on?
Option (b) fixes bugs in the current code. Currently 'get_random' is the
only caller of 'random'. If inefficiency is a problem after later code
changes, then then this issue can be revisited.
Another option is to replace the imlementation of 'random' in w32.c with
a different PRNG that can generate 31 bits more efficiently than using 3
calls to 'rand_as183'.
Yet another possibility is to use 'getrandom' from gnulib instead of all
of this Windows specific code, but that may bring a fresh set of
concerns to be considered.
AndyM
next prev parent reply other threads:[~2021-08-14 13:40 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-09-01 17:18 bug#32605: 26.1; (random) never returns negative Francis Wright
2018-09-01 17:34 ` Stephen Berman
2018-09-04 22:27 ` Noam Postavsky
2018-09-05 13:20 ` Andy Moreton
2021-08-12 13:17 ` bug#32605: [w64] " Lars Ingebrigtsen
2021-08-12 13:42 ` Eli Zaretskii
2021-08-12 20:34 ` Andy Moreton
2021-08-13 6:29 ` Eli Zaretskii
2021-08-13 21:12 ` Andy Moreton
2021-08-14 5:54 ` Eli Zaretskii
2021-08-14 8:31 ` Andy Moreton
2021-08-14 8:57 ` Eli Zaretskii
2021-08-14 11:06 ` Andy Moreton
2021-08-14 11:33 ` Eli Zaretskii
2021-08-14 12:10 ` Andy Moreton
2021-08-14 12:36 ` Eli Zaretskii
2021-08-14 13:40 ` Andy Moreton [this message]
2021-08-14 14:43 ` Eli Zaretskii
2021-08-14 18:47 ` Andy Moreton
2021-08-15 6:07 ` Eli Zaretskii
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=86a6lkywj0.fsf@gmail.com \
--to=andrewjmoreton@gmail.com \
--cc=32605@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).