bug-bash
[Top][All Lists]
Advanced

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

Re: Seeding $RANDOM in a subshell


From: Chet Ramey
Subject: Re: Seeding $RANDOM in a subshell
Date: Mon, 17 Jan 2005 14:52:12 -0500
User-agent: Mozilla Thunderbird 0.9 (Windows/20041103)

Chris F.A. Johnson wrote:

   On various platforms, with versions of bash from 1.14 to 3.0, I
   get:

$ RANDOM=1234567890; echo $RANDOM
2599
$ RANDOM=1234567890; echo $RANDOM
2599

   That's as it should be. But when I put that in a subshell (2.05b
   and 3.00):

$ ( RANDOM=1234567890; echo $RANDOM )
18681
$ ( RANDOM=1234567890; echo $RANDOM )
20498
$ ( RANDOM=1234567890; echo $RANDOM )
22315

   Bash 1.14 (as well as pdksh and ksh93) produces the same number
   every time.

Bash was changed at some point in the past to re-seed the random number
generator when a subshell was started, so the random sequence differed
in the parent and the subshell.

I have since made two changes that will address your concerns:  the
rng is only re-seeded once per subshell, and assigning a value to
RANDOM in the subshell counts as re-seeding.

Chet





reply via email to

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