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

Robert Kern robert.kern at gmail.com
Wed Jun 10 17:09:47 EDT 2009

On 2009-06-10 15:54, Mark Dickinson wrote:
> Robert Kern<robert.kern at gmail.com>  wrote:
>> On 2009-06-10 14:46, Mark Dickinson wrote:
>>> On Jun 10, 8:15 pm, Robert Kern<robert.k... at gmail.com>   wrote:
>>>> On 2009-06-10 13:53, Terry Reedy wrote:
>>>>> A full technical discussion does not below in the docs, in my opinion. A
>>>>> wike article would be fine.
>>>> True. However, a brief note that "Due to floating point arithmetic, for some
>>>> values of a and b, b may or may not be one of the possible generated results."
>>>> might be worthwhile. The actual details of *why* this is the case can be
>>>> discussed elsewhere.
>>> I find it difficult to see how such a disclaimer would have any
>>> practical value
>>> [lots more badly wrapped text snipped... ]
>> That's a fair point. However, one issue that hasn't been brought up is that it
>> might be confusing to a user why random.random() returns values in a half-open
>> interval while random.uniform() claims a closed interval. Even for reasonably
>> sophisticated floating point users, it's not necessarily obvious that that is
>> the reasoning behind the different claims.
> True.  I guess the original post in this thread is good evidence of
> that.  Though I'm not sure I'm capable of coming up with extra wording
> for the docs that won't just cause more confusion, so I'll leave that
> to someone else.

I did make a concrete suggestion.

> I seem to recall that when this originally came up in the tracker
> (issue 4979) the fun part of the analysis was proving that
> random.uniform(a, b) can never produce values *outside* the interval
> [a, b].  :-)

I was a bit worried about that part myself for a little bit. :-)

Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
  that is made terrible by our own mad attempt to interpret it as though it had
  an underlying truth."
   -- Umberto Eco

More information about the Python-list mailing list