Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: funny subshell effect
- X-seq: zsh-workers 28878
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh workers <zsh-workers@xxxxxxx>
- Subject: Re: funny subshell effect
- Date: Thu, 10 Mar 2011 06:56:53 -0800
- In-reply-to: <AANLkTi=VUkvqOxo+OANG2AVYko-Zbq7LwLQoF68fbLev@mail.gmail.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <AANLkTi=VUkvqOxo+OANG2AVYko-Zbq7LwLQoF68fbLev@mail.gmail.com>
On Mar 10, 12:18am, Mikael Magnusson wrote:
} Subject: funny subshell effect
}
} % repeat 3; do command echo .(e:REPLY=\$RANDOM:); done
} 5801
} 5801
} 5801
}
} Is this something that must be so?
Yep, it's intentional. Read the manual:
The values of RANDOM form an intentionally-repeatable pseudo-random
sequence; subshells that reference RANDOM will result in identical
pseudo-random values unless the value of RANDOM is referenced or
seeded in the parent shell in between subshell invocations.
Above that, "The random number generator can be seeded by assigning a
numeric value to RANDOM."
% for i in {1..3}; do command echo .(e:RANDOM=$i\;REPLY=\$RANDOM:); done
17767
6138
20026
If you're not generating more than one number per second, a good way
to see the generator is with $SECONDS. Or if your system supports a
higher granularity clock, something like
typeset -F SECONDS
repeat 3; do
command echo .(e:'RANDOM=$((SECONDS*1000));REPLY=$RANDOM':);
done
Consequently, Phil ... your approach may be reasonable, but we don't
want to apply it. :-)
Messages sorted by:
Reverse Date,
Date,
Thread,
Author