Hi there I am trying to generate a random number between 40 and 70 using the shell here is my code so far and it keeps going above 70. all help much appreciated!
comp=$(( RANDOM%70+40 ))
echo $comp
Hi there I am trying to generate a random number between 40 and 70 using the shell here is my code so far and it keeps going above 70. all help much appreciated!
comp=$(( RANDOM%70+40 ))
echo $comp
comp=$(( RANDOM%31+40 ))
If available on your flavor of 'nix, you can use the shuf command:
shuf -n 1 -i 40-70
thank you very much that worked perfectly
To generalize it:
MIN=10
MAX=20
echo $(( (RANDOM%((MAX-MIN)+1))+MIN))