perl function rand

ht‮spt‬://www.theitroad.com

The rand function in Perl is used to generate a random number between 0 and 1.

Here's an example:

# generate a random number between 0 and 1
my $random_number = rand();

print "Random number: $random_number\n";

# generate a random number between 0 and 10
my $random_number_10 = rand(10);

print "Random number (0-10): $random_number_10\n";

In this example, we first generate a random number between 0 and 1 using the rand() function and store it in the $random_number variable. We then print out the value of $random_number.

Next, we use the rand() function again to generate a random number between 0 and 10, and store it in the $random_number_10 variable. Finally, we print out the value of $random_number_10.