Linux and Networking

Linux and Networking

4.18. The generation of random numbers.

Generating random numbers in shell script is done using the $RANDOM variable.

In the following example you can see how this variable works:

 

$ echo $RANDOM

22772

$ echo $RANDOM

14193

$ echo $RANDOM

6903

Let’s see an example of use in a shell script. In the following example, 10 random numbers will be generated:

Suggested exercises

1 Generate 10 random numbers greater than 10 and less than 1000

2 Make a program that proposes primitive combinations (5 numbers + complementary all different)

The Demeter Project