5 ms·
> GNU Bash has a magic variable RANDOM that produces random numbers. Assignments to it appear to be ignored. Assignments are used to seed¹ the random number ge
by JNRowe 7y ago
> GNU Bash has a magic variable RANDOM that produces random numbers. Assignments to it appear to be ignored.
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 https://en.m.wikipedia.org/wiki/Random_seed
2. https://en.m.wikipedia.org/wiki/Random_number_generator https://en.m.wikipedia.org/wiki/Random_number_generator
3. https://en.m.wikipedia.org/wiki//dev/random https://en.m.wikipedia.org/wiki//dev/random
4. https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=828180 https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=828180