Perl srand Function



Description

This function sets the seed value for the random number generator to EXPR or to a random value based on the time, process ID, and other values if EXPR is omitted

Syntax

Following is the simple syntax for this function −

srand EXPR

srand

Return Value

This function does not return any value.

Example

Following is the example code showing its basic usage −

#!/usr/bin/perl -w

srand(26);
print("Here's a random number:        ", rand(), ".\n");
srand(26);
print("Here's the same random number: ", rand(), ".\n");

When above code is executed, it produces the following result −

Here's a random number:        0.811688061411591.
Here's the same random number: 0.811688061411591.
perl_function_references.htm
Advertisements