Sorting NaNs

Chris Angelico rosuav at gmail.com
Thu Jun 7 03:52:29 EDT 2018


On Thu, Jun 7, 2018 at 2:14 PM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
> On Sat, 02 Jun 2018 21:02:14 +1000, Chris Angelico wrote:
>
>> Point of curiosity: Why "> 0.5"?
>
> No particular reason, I just happened to hit that key and then copied and
> pasted the line into the next one.

Hah! The simplicity of it.

>> Normally when I want a fractional
>> chance, I write the comparison the other way: "random.random() < 0.5"
>> has exactly a 50% chance of occurring (presuming that random.random()
>> follows its correct documented distribution). I've no idea what the
>> probability of random.random() returning exactly 0.5 is
>
> Neither do I. But I expect that "exactly 50% chance" is only
> approximately true :-)

Oh, I have no doubt about that. (Though as Gregory says, the
uniformity is based on the PRNG more than on any enumeration of
floats. There are probably floating-point values between 0.0 and 1.0
that can never actually be returned.)

> So given that our mathematically pure(ish) probability of 0.5 for the
> reals has to be mapped in some way to a finite number of floats, I
> wouldn't want to categorically say that that the probability remains
> *precisely* one half. But if it were (let's say) 1 ULP greater or less
> than one half, would we even know?
>
> 0.5 - 1 ULP = 0.49999999999999994
>
> 0.5 + 1 ULP = 0.5000000000000001
>
>
> I would love to see the statistical experiment that could distinguish
> those two probabilities from exactly 1/2 to even a 90% confidence
> level :-)

LOL, no kidding. How many RNG rolls would you need before you could
even distinguish between 50-50 and 49-51% chance? How many people have
done any sort of statistical analysis even that accurate?

ChrisA



More information about the Python-list mailing list