A random number generator in Bash


The bash environment variable ‘RANDOM’ is a pseudo-random number generator built in bash, and it can generate random numbers in the range of 0 – 32767.

Using the command `echo $RANDOM`, we can generate a random number. Building a random number generator which emits a sequence of random numbers is pretty easy.

#!/bin/bash
for i in `seq 1 10`:
do
echo $RANDOM;
sleep 1s;
done

The ‘seq’ or the ‘sequential’ can be used to generate a sequence of numbers.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s