$RANDOM
–
Random Integer
$RANDOM
expands to a random integer in the range [0, 32767]
.
Assigning a values seeds the random name generator.
The random generator generates the same numbers in subshells unless you seed it.
Links
Examples
- Seed random generator and print random value
- Output:
1 2 3 4 5 6 7 8 9 10 11
# without seeding, the same numbers are generated in subshells echo "subshell 1: $(echo $RANDOM)" echo "subshell 2: $(echo $RANDOM)" # seed with "seconds since epoch" followed by "nanoseconds" to enforce different values RANDOM=$(date +%s%N) echo "after seeding: subshell 1: $(echo $RANDOM)" sleep .1 RANDOM=$(date +%s%N) echo "after seeding: subshell 2: $(echo $RANDOM)"
1 2 3 4
subshell 1: 26215 subshell 2: 26215 after seeding: subshell 1: 23977 after seeding: subshell 2: 1130
BashSupport Pro ist eine Zsh IDE mit Unterstützung für $RANDOM - probieren Sie es jetzt aus!