O'Reilly logo

Learning AWK Programming by Shiwang Kalkhanda

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The srand ([expr]) function 

The srand([expr]) function generates the random number with the given argument integer set as the seed value. Whenever the program execution starts, AWK generates its random number from the seed value that is given as the argument. If no argument is given, AWK uses the time of day to generate the seed, and thus, without an argument, it always generates different random numbers.

Generally, the srand ([expr]) function is used to set the seed value for the rand function and then the rand() function is used for random value creation. The following code block shows an example of a srand ([expr]) function:

$ vi srand1.awkBEGIN    {    print "Random num1 = ", srand()    print "Random num2 = ", srand()}$ awk -f srand1.awk

The ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required