New submission from David MacIver <[email protected]>:
The following code raises a ZeroDivisionError:
from random import Random
Random(14064741636871487939).paretovariate(0.01)
This raises:
random.py, line 692, in paretovariate
return 1.0 / u ** (1.0/alpha)
ZeroDivisionError: float division by zero
That specific stack trace is from 3.8.5 but I've tried this on 3.6 and 3.7 as
well.
It's a little hard to tell what the intended correct range of parameter values
is for paretovariate, and this may just be lack of validation for the alpha < 1
case - perhaps that was never intended to be supported?
Based on some very informal inspection, what seems to happen is that the
probability of getting a ZeroDivisionError approaches one as you approach zero.
They rarely occur at this level of alpha (0.01), but for alpha=0.001 they seem
to occur just under half the time, and for alpha=0.0001 they occur more than
90% of the time.
(For the interested, this bug was found by Hypothesis as part of its own
testing of our integration with the Random API)
----------
components: Library (Lib)
messages: 374516
nosy: David MacIver
priority: normal
severity: normal
status: open
title: Random.paretovariate sometimes raises ZeroDivisionError for small alpha
versions: Python 3.6, Python 3.7, Python 3.8
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue41421>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com