in reply to generating random numbers within a range

rand takes a scalar value and generates a randomish number in the range 0..value-1. You are passing it an array. Try this:
# other code here $rand = int(rand($high - $low) + $low); # other code here
Note that this will result in a number >= $low but < high.

Replies are listed 'Best First'.
Re^2: generating random numbers within a range
by xdg (Monsignor) on May 09, 2005 at 21:01 UTC

    Let me suggest looking at Math::Random::OO -- particularly Math::Random::OO::UniformInt. (Disclaimer -- I wrote it). It will help avoid typical errors that creep in. (OBO, etc.)

    use Math::Random::OO 'UniformInt'; my $prng = UniformInt(1,10); print $prng->next; # integer between 1 and 10 inclusive

    -xdg

    Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.