Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Random numbers in functions
- X-seq: zsh-users 12245
- From: Justin M Wozniak <jwozniak@xxxxxxxxxx>
- To: zsh-users@xxxxxxxxxx
- Subject: Re: Random numbers in functions
- Date: Tue, 20 Nov 2007 14:30:39 -0500 (EST)
- In-reply-to: <200711201823.lAKIN5oM011816@xxxxxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <200711201823.lAKIN5oM011816@xxxxxxxxxxxxxx>
Thanks! But since I'm planning to obtain many random numbers I'd like to
do this without file operations. Using a global variable should be
equivalent to your solution but the output of rand48() seems to be
convergent.
Is the seed or the state of the generator saved?
Here's a simplified version of what I'm looking at:
The lib (functions.zsh):
typeset -g RANDOM_PARAMETER="abcabcabcabc"
random()
{
print "RP: $RANDOM_PARAMETER"
T=$(( rand48(RANDOM_PARAMETER) * 1000 ))
print "RP: $RANDOM_PARAMETER"
RESULT=$(( T % 10 ))
print "RESULT: ${RESULT}"
print
}
The call:
source functions.zsh
for i in {1..4} ; { print "TOP_RP: $RANDOM_PARAMETER" ; random }
The result:
TOP_RP: abcabcabcabc
RP: abcabcabcabc
RP: 004db541003a
RESULT: 0
TOP_RP: 004db541003a
RP: 004db541003a
RP: 004db541003a
RESULT: 0
TOP_RP: 004db541003a
RP: 004db541003a
RP: 004db541003a
RESULT: 0
TOP_RP: 004db541003a
RP: 004db541003a
RP: 004db541003a
RESULT: 0
--
Justin Michael Joseph Wozniak
On Tue, 20 Nov 2007, Peter Stephenson wrote:
Messages sorted by:
Reverse Date,
Date,
Thread,
Author