Programming Perl

Programming PerlSearch this book
Previous: 3.2.114 quotemetaChapter 3
Functions
Next: 3.2.116 read
 

3.2.115 rand

rand EXPR
rand

This function returns a random fractional number between 0 and the value of EXPR. (EXPR should be positive.) If EXPR is omitted, the function returns a value between 0 and 1 (including 0, but excluding 1). See also srand.

To get an integral value, combine this with int, as in:

$roll = int(rand 6) + 1;       # $roll is now an integer between 1 and 6


Previous: 3.2.114 quotemetaProgramming PerlNext: 3.2.116 read
3.2.114 quotemetaBook Index3.2.116 read