bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: $RANDOM not random in 2.05.0(1)-release


From: Chet Ramey
Subject: Re: $RANDOM not random in 2.05.0(1)-release
Date: Wed, 27 Mar 2002 08:56:07 -0500

>     while true; do echo -n " $(( ( RANDOM >> 5) % 8 ))"; done
> 
> Shows a repeat interval of 256 (look for 6 6 0 0 0 1 1)
> 
>     while true; do
>        R=$RANDOM
>        R=$(( ( RANDOM >> 5) % 8 ))
>        echo -n " $R"
>     done
> 
> Shows the same
> 
>   Although the basic PRNG is fairly good (period 2^31-1), and BASH strips
> off the low order bits already, the net result that appears in $RANDOM is
> horrid for some reason.
> 
> ### from bash-2.05a/variables.c ######################################

The first thing to check is whether the results are different for bash-2.05a.
You're testing bash-2.05 and looking at the 2.05a source.  One of the changes
in 2.05a was the stripping of the low-order bits of $RANDOM.

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
( ``Discere est Dolere'' -- chet)

Chet Ramey, CWRU    address@hidden    http://cnswww.cns.cwru.edu/~chet/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]