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

2020-08-01 Thread Raymond Hettinger
Raymond Hettinger added the comment: Okay, marking this as closed. -- resolution: -> works for me stage: patch review -> resolved status: open -> closed ___ Python tracker __

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

2020-08-01 Thread Tim Peters
Tim Peters added the comment: That text is fine, if you feel something needs to be said at all. I really don't. A Pareto distribution of this kind with parameter <= 1.0 has infinite expected value - VERY long tail. Anyone who knows what they're doing already knows that. The reason the implem

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

2020-08-01 Thread Raymond Hettinger
Raymond Hettinger added the comment: How about this wording? If alpha is smaller than 0.1, an occasional OverflowError can arise when the variate exceeds the range of Python float. I like using 0.1 because it's easy and gives us some wiggle room. The actual cutoff is lower: >>>

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

2020-08-01 Thread Raymond Hettinger
Raymond Hettinger added the comment: New changeset 5c3270939c09e4c8e80fd26449b718a998701912 by Raymond Hettinger in branch 'master': bpo-41421: Algebraic simplification for random.paretovariate() (GH-21695) https://github.com/python/cpython/commit/5c3270939c09e4c8e80fd26449b718a998701912 --

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

2020-07-31 Thread Raymond Hettinger
Change by Raymond Hettinger : -- keywords: +patch pull_requests: +20839 stage: -> patch review pull_request: https://github.com/python/cpython/pull/21695 ___ Python tracker __

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

2020-07-29 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: +1 for "u ** (-1.0 / alpha)"! -- ___ Python tracker ___ ___ Python-bugs-list mailing list Unsub

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

2020-07-29 Thread David MacIver
David MacIver added the comment: I should say, I don't actually care about this bug at all: I only ran into it because of trying to recreate the random API and testing that my recreation worked sensibly. I thought I'd do the good citizen thing and report it, but I'm totally fine with any res

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

2020-07-28 Thread Raymond Hettinger
Raymond Hettinger added the comment: I don't feel a need to change anything, my post hit a few seconds after yours :-) That said, "return u ** (-1.0 / alpha)" would be a slight, but nice improvement. It might also be reasonable to document a safe range of alpha values. --

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

2020-07-28 Thread Tim Peters
Tim Peters 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. Whi

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

2020-07-28 Thread Raymond Hettinger
Raymond Hettinger added the comment: The point of the "u = 1.0 - self.random()" line was to prevent the case where *u* was exactly equal to zero; however, as you noted, raising a very small number to a small can round down to zero. We could wrap the calculation in a try/except to catch the Z

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

2020-07-28 Thread Raymond Hettinger
Change by Raymond Hettinger : -- type: -> behavior versions: +Python 3.10, Python 3.9 -Python 3.6, Python 3.7 ___ Python tracker ___ __

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

2020-07-28 Thread Tim Peters
Tim Peters added the comment: I'm inclined to ignore this. No actual user has complained about this, and I doubt any ever will: it's got to be rare as hen's teeth to use a parameter outside of, say, [0.1, 10.0], in real life. The division error can't happen for those. For "small" alpha, the

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

2020-07-28 Thread Raymond Hettinger
Change by Raymond Hettinger : -- nosy: +tim.peters ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://ma

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

2020-07-28 Thread Serhiy Storchaka
Change by Serhiy Storchaka : -- nosy: +serhiy.storchaka ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https

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

2020-07-28 Thread Karthikeyan Singaravelan
Change by Karthikeyan Singaravelan : -- nosy: +mark.dickinson, rhettinger ___ Python tracker ___ ___ Python-bugs-list mailing list U

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

2020-07-28 Thread David MacIver
David MacIver added the comment: I guess on actual inspection of the code (which I should have done before, sorry) it's obvious why this happens: u ** (1.0 / alpha) will round to 0.0 for small values of u, and the smaller alpha is the higher the probability of that happening, in that it happ

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

2020-07-28 Thread David MacIver
New submission from David MacIver : 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 Tha