How to Generate Random Number with Bash Scripting

Sometimes we need to generate random number, there are many online random generator nowadays on the internet, but how if we don’t have internet connection to open random generator ?. Don’t worry Bash shell provides a $RANDOM variable, with this variable you can generate a random number between 0 to 32767.

To generate a random number, use this simple command :

$ echo $RANDOM

Now look at the output, also you can use a loop to generate numbers :

for n in {1..3}; do echo $RANDOM; done

This command will generate random number three times.

If you want more information, i recommend you to read the man pages :

$ man bash

$ man 4 random

$ man od

Hope this quick post help you a lot to generate numbers, if you have question you can leave it on the comment section below, thank you !