Generate Random Number With Bash Script

I use this script to generate random numbers.  This is useful if something needs a random time delay (for network performance issues) or choosing a random selection from a case  statement.

#!/bin/bash
RANGE=90
number=$RANDOM
let "number %=$RANGE"
echo "$number is a random number less than $RANGE"

You can change RANGE  to be any number you want to lower or increase the randomness.

case $number in
	1) echo "Do this.";;
	2) echo "Do something else.";;
	3) echo "Random each time.";;
	*) echo "If all else fails.";;
esac

 

Leave a Reply