in reply to inclusive rand
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!
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: inclusive rand
by msh210 (Monk) on Mar 13, 2017 at 12:44 UTC | |
by Eily (Monsignor) on Mar 13, 2017 at 13:07 UTC | |
by msh210 (Monk) on Mar 13, 2017 at 13:09 UTC | |
by LanX (Saint) on Mar 13, 2017 at 12:52 UTC | |
by msh210 (Monk) on Mar 13, 2017 at 13:03 UTC | |
by LanX (Saint) on Mar 13, 2017 at 13:02 UTC | |
by msh210 (Monk) on Mar 13, 2017 at 13:05 UTC | |
by LanX (Saint) on Mar 13, 2017 at 13:12 UTC | |
by LanX (Saint) on Mar 13, 2017 at 13:32 UTC | |
by LanX (Saint) on Mar 13, 2017 at 15:19 UTC | |
by pryrt (Abbot) on Mar 13, 2017 at 16:06 UTC | |
| |
by msh210 (Monk) on Mar 13, 2017 at 16:01 UTC |