[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#32605: [w64] (random) never returns negative
From: |
Andy Moreton |
Subject: |
bug#32605: [w64] (random) never returns negative |
Date: |
Sat, 14 Aug 2021 14:40:35 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (windows-nt) |
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
- bug#32605: [w64] (random) never returns negative, (continued)
- bug#32605: [w64] (random) never returns negative, Andy Moreton, 2021/08/12
- bug#32605: [w64] (random) never returns negative, Eli Zaretskii, 2021/08/13
- bug#32605: [w64] (random) never returns negative, Andy Moreton, 2021/08/13
- bug#32605: [w64] (random) never returns negative, Eli Zaretskii, 2021/08/14
- bug#32605: [w64] (random) never returns negative, Andy Moreton, 2021/08/14
- bug#32605: [w64] (random) never returns negative, Eli Zaretskii, 2021/08/14
- bug#32605: [w64] (random) never returns negative, Andy Moreton, 2021/08/14
- bug#32605: [w64] (random) never returns negative, Eli Zaretskii, 2021/08/14
- bug#32605: [w64] (random) never returns negative, Andy Moreton, 2021/08/14
- bug#32605: [w64] (random) never returns negative, Eli Zaretskii, 2021/08/14
- bug#32605: [w64] (random) never returns negative,
Andy Moreton <=
- bug#32605: [w64] (random) never returns negative, Eli Zaretskii, 2021/08/14
- bug#32605: [w64] (random) never returns negative, Andy Moreton, 2021/08/14
- bug#32605: [w64] (random) never returns negative, Eli Zaretskii, 2021/08/15