Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

rigorously predictable random numbers



#!/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