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    c...@case.edu    http://tiswww.cwru.edu/~chet/

Reply via email to