[issue41421] Random.paretovariate sometimes raises ZeroDivisionError for small alpha

Tim Peters report at bugs.python.org
Tue Jul 28 19:54:41 EDT 2020


Tim Peters <tim at python.org> added the comment:

BTW, if we have to "do something", how about changing

return 1.0 / u ** (1.0/alpha)

to the mathematically equivalent

return (1.0 / u) ** (1.0/alpha)

? Not sure about Linux-y boxes, but on Windows that would raise OverflowError instead of ZeroDivisionError. Which makes more sense, because the Pareto variable we're _trying_ to produce is too large to represent.  If it returns math.inf on some box instead, same thing.

Or, also faster, and suffering fewer rounding errors,

return  u ** (-1.0 / alpha)

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue41421>
_______________________________________


More information about the Python-bugs-list mailing list