Generate Random Number using Bash Shell Script
In this post, I am going to share how to generate random numbers using Bash Shell.
The bash shell offers a $RANDOM variable to generate random numbers. It is a kernel random number source device.
To view $RANDOM
echo $RANDOM
# display a random integer <= 20
echo $(( RANDOM%= 20 ))
# display random number between 0 and 20.
echo $((RANDOM%20+0))
Script to Generate 10 Random Numbers
n=$RANDOM
for i in {1..10}
do
echo $((RANDOM%20+0))
done
Manual Page for Random
man 4 random
Post a Comment
Post a Comment