No such thing as a small change | |
PerlMonks |
Re: Re: Random numbers generationby pizza_milkshake (Monk) |
on May 21, 2004 at 16:58 UTC ( [id://355347]=note: print w/replies, xml ) | Need Help?? |
this will generate numbers between 250 and 499 because of the behaviors of rand and int:
rand Returns a random fractional number greater than or equal to 0 and less than the value of EXPR. int Returns the integer portion of EXPR. If EXPR is omitted, uses $_. You should not use this function for rounding: one because it trun-cates towards 0, and two because machine representations of floating point numbers can sometimes produce counterintuitive results. rand(250) will always return a number less than 250 and int will never round up. use rand(251) perl -e"\$_=qq/nwdd\x7F^n\x7Flm{{llql0}qs\x14/;s/./chr(ord$&^30)/ge;print"
In Section
Seekers of Perl Wisdom
|
|