start page | rating of books | rating of authors | reviews | copyrights

Perl in a Nutshell

Perl in a NutshellSearch this book
Previous: Reference: quotemeta Chapter 5
Function Reference
Next: Reference: read
 

rand

rand 
num

Returns a random fractional number between 0 and the value of num . ( num should be positive.) If num 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: Reference: quotemeta Perl in a Nutshell Next: Reference: read
Reference: quotemeta Book Index Reference: read

Library Navigation Links

Copyright © 2001 O'Reilly & Associates. All rights reserved.