Jump to content

Perl Programming/Keywords/rand

From Wikibooks, open books for an open world
Previous: qx Keywords Next: read

The rand keyword

[edit | edit source]

rand is a function that returns a random fractional number greater than or equal to 0 and less than the value of EXPRESSION. Without EXPRESSION, the value 1 is used so that the interval of the random number is .

Syntax

[edit | edit source]
  rand EXPRESSION
  rand

Examples

[edit | edit source]
The code
$a = rand(31);
print 'int(' . "$a" . ') = ', int($a);
returns a number [0, 31) like
 int(28.7540893554688) = 28

See also

[edit | edit source]
Previous: qx Keywords Next: read