bug-bash
[Top][All Lists]
Advanced

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

Re: Documentation: RANDOM=0 resets the seed


From: Chet Ramey
Subject: Re: Documentation: RANDOM=0 resets the seed
Date: Mon, 24 Jan 2011 20:19:15 -0500
User-agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.8) Gecko/20100802 Lightning/1.0b2 Thunderbird/3.1.2

On 1/23/11 10:53 PM, Olivier Mehani wrote:
> Hi,
> 
> I'm using Bash's $RANDOM variable to create repeatable sequences of
> pseudo-random numbers. I used seeds >= 0, and noticed random
> non-repeatable sequences for RANDOM=0, which I didn't expect given the
> documentation.
> 
> Looking at the code, it appears that RANDOM=0 has a specific value,
> which appears to be “seed not initialised,” and triggers an
> initialisation on the next call. I think this characteristic has to be
> made explicit in the documentation, to avoid bad surprises.

You're right, it's a definite issue.  The sequence produced by a given
seed should always be the same.  The reason that RANDOM=0 produces
special behavior, though, is that the random number generator just does
not work when the seed is 0.

The right fix is to assign some constant value to rseed when it is 0,
preserving the repeatable sequence property.

Chet


-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    chet@case.edu    http://cnswww.cns.cwru.edu/~chet/



reply via email to

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