But that's exactly the point, because in practical use you want an "integer resolution". (don't know how to phrase it better, look at the examples)
This will produce all values between 0 and 10 inclusively perl -E"say int rand(11) for 1..20"
and this will produce them between 0 and 1 inclusively in 0.1 steps
C:\Windows\system32>perl -E"say 0.1 * int rand(11) for 1..20"
just improve the resolution if 0.1 is not enough, like in
C:\Windows\system32>perl -E"say 1e-6 * int rand(1e6+1) for 1..20"
or with full abstraction
perl -E" $res=1e6; say 1/$res * int rand($res+1) for 1..20"
Please keep in mind that this is not cheating because in perl floats don't have anything like an infinite resolution.
That's why the probability is not 0 like you thought.
Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!
In reply to Re: inclusive rand
by LanX
in thread inclusive rand
by msh210
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |