[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Use high bits of the raw random number?
From: |
Chet Ramey |
Subject: |
Re: Use high bits of the raw random number? |
Date: |
Tue, 14 May 2019 14:50:09 -0400 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 |
On 5/9/19 10:29 AM, Peng Yu wrote:
> Hi,
>
> Bash uses the low 16 bits for $RANDOM.
>
> https://git.savannah.gnu.org/cgit/bash.git/tree/variables.c#n1321
> https://git.savannah.gnu.org/cgit/bash.git/tree/variables.c#n1356
>
> It seems that the high bits should be more random. If so, maybe the
> high 16 bits should be kept if $RANDOM must stay in 16bits?
This seems like something you could test and verify.
Change the random number generator in variables.c:brand() to return
the high 16 bits ((rseed >> 16) & 32767) and compare the behavior against
the existing version over 32768 $RANDOM generations.
If you wanted to try a third alternative, you could XOR the high 16 bits
with the low 16 and return that.
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU chet@case.edu http://tiswww.cwru.edu/~chet/