Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

rand

Returns a pseudo-random floating-point number.

Returns a pseudo-random floating-point number greater than or equal to 0 and less than EXPR (or 1 if omitted). If EXPR evaluates to zero, 1.0 is used instead. Uses the interpreter’s StdRng state, which can be seeded via srand. Not suitable for cryptographic purposes.

Synopsis

my $r = rand;          # 0 <= $r < 1
my $r = rand(10);      # 0 <= $r < 10
my $r = rand($n);

See Also

srand, int