> Naturally, the probability of getting 1 is 0 anyway, so this has little practical use, but I'm curious.

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"

edit

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.