My intention is to use `expr $RANDOM / value` to narrow the randomness down to a range. However, this always returns the same number. A more pure test case is:
echo `echo $RANDOM`.
I assume the subshell is always spawned with the same random seed.
Suggestions: Set an environment variable SEED to a new random value before spawning a subshell, and then make zsh use this SEED variable as random seed.
Alternatively: read a new seed from /dev/urandom when a shell (also a subshell) is spawned.
The variables are replaced before the call of the sub-shell
For example echo `echo $$` will always give you the pid of the main shell.
So this bug is even weirder, it's not a subshell problem, maybe caching of variables before subshell calls.
echo $RANDOM will print the same value you had with the last echo `echo $RANDOM` and change it.
Then, doing echo `echo $RANDOM` will give you a new number, but always the same until you call echo $RANDOM.