in reply to random number with range
Just use the rand function. It generates numbers in a half open interval ranging from (and including) 0 through to (but not including) the positive number given (or 1 if omited). The result is a real number (not an integer) in that range. If you want to pick an integer between $start and $end inclusive you can do this:
my $number = $start + int rand $end - $start + 1;
$end must be >= $start.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: random number with range
by Anonymous Monk on Apr 04, 2020 at 19:28 UTC | |
by Your Mother (Archbishop) on Apr 05, 2020 at 02:39 UTC |