问题
I've seen many other ways to do this in other programming languages... Though I havent found one in Perl yet...
What I want to accomplish is to set two numbers:
$minimum = 100;
$maximum = 4000;
Then to create a random integer between those two. (whole number) ($random_num)
I've looked into this site: http://perlmeme.org/howtos/perlfunc/rand_function.html
Which is a good resource, although does not do exactly that.
回答1:
my $x = $minimum + int(rand($maximum - $minimum));
http://perldoc.perl.org/functions/rand.html
Note this range excludes $maximum
itself. Add 1 to make it inclusive.
回答2:
my $random_num = int($minimum + rand($maximum - $minimum));
来源:https://stackoverflow.com/questions/21806362/how-can-i-create-a-random-number-between-two-numbers-in-perl