Случайные числа

Простые типы / Числа / Integer

#RANDOM gives a new whole number from 0 to 32767 on every read;
#assigning a number to it sets the seed, so the sequence repeats
RANDOM=42

rand=$((RANDOM % 3))
#rand is 0, 1 or 2

#a number from min to max inclusive
min=10
max=20
inRange=$((min + RANDOM % (max - min + 1)))
#inRange is from 10 to 20

#shuf picks numbers from a range, a new one on every run
fromShuf=$(shuf -i 1-10 -n 1)
#fromShuf is from 1 to 10, it has no seed, so it is not printed here

echo "rand is $rand"
echo "inRange is $inRange"