random number including 1 - i.e. [0,1]

Andre Engels andreengels at gmail.com
Wed Jun 10 03:30:49 EDT 2009


On Wed, Jun 10, 2009 at 8:25 AM, John Yeung<gallium.arsenide at gmail.com> wrote:

> That uniform(a, b) will return a random float in the semi-open
> interval [a, b) for certain values of a and b; and in the closed
> interval [a, b] for other values of a and b.  (Swap a and b if a > b.)
>
> To me, the fact that you sometimes get a semi-open interval and
> sometimes a closed interval is worth noting in the docs.

If it is important whether "b" is included or not, apparently the
difference between "b" and "the largest float smaller than b" is
important. If a difference as small as that makes a difference, you
should not be using floats, or random generators giving floats,
anyway, but something with a higher precision.

In other words, if you do care about the difference between [a, b) and
[a, b], the random module is not giving what you meet even if it does
give the 'right' one of those.

-- 
André Engels, andreengels at gmail.com



More information about the Python-list mailing list