Does shuffle() produce uniform result ?

Mark Dickinson dickinsm at gmail.com
Fri Aug 24 22:03:39 EDT 2007


On Aug 24, 9:30 pm, Mark Dickinson <dicki... at gmail.com> wrote:

> x = floor((n/2**53)*7)
>
> will produce 0, 1, 3 and 5 with probability (2**53//7+1)/2**53, and 2,
> 4 and 6 with probability (2**53//7)/2*53.

Oops---I lied;  I forgot to take into account the rounding implicit in
the (n/2**53)*7 multiplication.  A bit of experimentation shows that
it's 0, 2, 4 and 6 that occur more often, with 1, 3 and 5 less likely
by a miniscule amount (at least on an IEEE-754 system).

Mark




More information about the Python-list mailing list