Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
rigorously predictable random numbers
- X-seq: zsh-users 29869
- From: Ray Andrews <rayandrews@xxxxxxxxxxx>
- To: Zsh Users <zsh-users@xxxxxxx>
- Subject: rigorously predictable random numbers
- Date: Thu, 2 May 2024 18:23:15 -0700
- Archived-at: <https://zsh.org/users/29869>
- List-id: <zsh-users.zsh.org>
#!/usr/bin/zsh
echo $RANDOM
var=$( echo $RANDOM )
echo $var
... I run that and get:
3 /aWorking/Zsh/Source/Wk 1 % . test1
23008
3809
3 /aWorking/Zsh/Source/Wk 1 % . test1
3809
768
3 /aWorking/Zsh/Source/Wk 1 % . test1
768
11071
3 /aWorking/Zsh/Source/Wk 1 % . test1
11071
26432
3 /aWorking/Zsh/Source/Wk 1 % . test1
26432
19059
3 /aWorking/Zsh/Source/Wk 1 % . test1
19059
14427
... the result of the first $RANDOM is always exactly the result
of the second $RANDOM in the previous call to the script. This
might not be as unexpected in a function where at least it's the
same shell, but a script, seems to me, should always have a
virginal notion of $RANDOM, no? Yet it remembers the previous
result from another shell. I have the vaguest fragment of memory
that we discussed this on the list once before.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author