in reply to Re: generating random numbers within a range
in thread generating random numbers within a range

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.