|
|
|
|
|
by kazinator
2254 days ago
|
|
Classic BASIC implementation picked up on this idea. For instance some dialects had an INKEY$ variable which looks like a string, but magically reads console input. GNU Bash has a magic variable RANDOM that produces random numbers. Assignments to it appear to be ignored. In Algol, the name of the enclosing function acts as a variable to which you assign in order to produce the return value. For instance, see the assignment to B in the nested function here; https://en.wikipedia.org/wiki/Man_or_boy_test |
|
Assignments are used to seed¹ the random number generator². This isn't limited to just bash/zsh/etc, it is intrinsic to the process of generating random numbers. Being aware of this is useful as it poses a significant footgun. The /dev/random docs³ provide a nice overview of how it is often handled on various systems at the OS level to deal with reboots.
An example of the fun that this can produce can be seen in a Debian bug⁴, running a script that uses subshells and RANDOM with bash will behave very differently when using zsh. In this instance you have to hope that subshells aren't being used to create unique logs as an example.
1. https://en.m.wikipedia.org/wiki/Random_seed
2. https://en.m.wikipedia.org/wiki/Random_number_generator
3. https://en.m.wikipedia.org/wiki//dev/random
4. https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=828180