in reply to
Need help with number generator
how about
$random = 2 + ( 8 <=> int( rand( 10 ) ) );
The <=> returns -1, 0, or 1, so you'll get -1 + 2 = 1 if its less than 8, 2 if its equal to 8, or 3 if it is greater than 8.
Comment on
Re: Need help with number generator
Download
Code
Replies are listed 'Best First'.
RE: Re: Need help with number generator
by
meonkeys
(Chaplain)
on Aug 10, 2000 at 02:08 UTC
This idea rocks. But I think this is correct
$random = 2 + ( int( rand( 10 ) ) <=> 8 );
[download]
this will make
$random = 1 ...... 80% of the time
$random = 2 ...... 10% of the time
$random = 3 ...... 10% of the time
[reply]
[d/l]
In Section
Seekers of Perl Wisdom