I'm trying to get my script to pause randomly between 20 and 10 seconds where the max amount of time is 20 and minimum 10. I'm using this atm:
sleep $((10 + RANDOM % 20));But the problem is that it disregards the limit of 20 and goes beyond that. Is there an other way?
11 Answer
10 and 20 are not min and max of the RANDOM number.
The expression is simple math. % means modulo.
You want
sleep $((10 + RANDOM % 11));It's 11 because 10-20 are 11 numbers.
Alternatively, you could use shuf:
sleep $(shuf -i 10-20 -n 1) 2