Generating random number between two numbers

We have a requirement to generate random number .In this we will use shell script to generate random number between 0 and 99 .

We will be using a simple mathematical trick to achieve this using % operator .

The $$ variable is the PID (Process IDentifier) of the currently running shell.

To generate a random number in a UNIX or Linux shell, the shell maintains a shell variable named RANDOM. Each time this variable is read, a random number between 0 and 32767 is generated.

With this we can see random numbers generated between 0 to 99 . If we want to get for another range then we will use different number .Just replace 100 with the required target number .

above script looks like below some part of output is shown .

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *