Skip to content

Commit 5c32709

Browse files
authored
bpo-41421: Algebraic simplification for random.paretovariate() (GH-21695)
1 parent cadda52 commit 5c32709

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

Lib/random.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ def paretovariate(self, alpha):
749749
# Jain, pg. 495
750750

751751
u = 1.0 - self.random()
752-
return 1.0 / u ** (1.0 / alpha)
752+
return u ** (-1.0 / alpha)
753753

754754
def weibullvariate(self, alpha, beta):
755755
"""Weibull distribution.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Make an algebraic simplification to random.paretovariate(). It now is
2+
slightly less subject to round-off error and is slightly faster. Inputs that
3+
used to cause ZeroDivisionError now cause an OverflowError instead.

0 commit comments

Comments
 (0)