cross python version randomness

Robin Becker robin at reportlab.com
Tue Mar 21 05:30:55 EDT 2017


..........
>>
>> presumably randint is doing something different to get its values.
>
>
> The docs [https://docs.python.org/3/library/random.html#random.randrange]
> for randrange have this note:
>
> Changed in version 3.2: randrange() is more sophisticated about producing
> equally distributed values. Formerly it used a style like int(random()*n)
> which could produce slightly uneven distributions.
>
> Maybe that's the explanation?  Unfortunately I don't have an install of
> 3.0/1 to test against.
>

Looking in random.py it sesms to be true. Pity no backwards compatibility mode. 
I don't actually care about the quality of the ints produced, but I do care 
about reproducibility, luckily I think it's feasible to monkey patch the 2.7 
method back in.
-- 
Robin Becker



More information about the Python-list mailing list