Monday, July 25, 2016

Shell Script :generating random numbers

Generating random numbers is bit easier as compare to generating random numbers in other languages.

To generate a random number in shell script use below command
$RANDOM

The above command is case sensitive and hence $random will not give you desire result.

Generating  random number with in a range
lr=100 # lower range
ur=600 # upper range
r=`expr $ur - $lr`
echo "The random number of `expr $RANDOM % $r + $lr`"


-Thank you

No comments:

Post a Comment