[Python-checkins] bpo-41421: Algebraic simplification for random.paretovariate() (GH-21695)

Raymond Hettinger webhook-mailer at python.org
Sat Aug 1 04:18:51 EDT 2020


https://github.com/python/cpython/commit/5c3270939c09e4c8e80fd26449b718a998701912
commit: 5c3270939c09e4c8e80fd26449b718a998701912
branch: master
author: Raymond Hettinger <rhettinger at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2020-08-01T01:18:26-07:00
summary:

bpo-41421: Algebraic simplification for random.paretovariate() (GH-21695)

files:
A Misc/NEWS.d/next/Library/2020-08-01-00-51-15.bpo-41421.dHKRVB.rst
M Lib/random.py

diff --git a/Lib/random.py b/Lib/random.py
index a6454f520df0a..37f71110403ad 100644
--- a/Lib/random.py
+++ b/Lib/random.py
@@ -749,7 +749,7 @@ def paretovariate(self, alpha):
         # Jain, pg. 495
 
         u = 1.0 - self.random()
-        return 1.0 / u ** (1.0 / alpha)
+        return u ** (-1.0 / alpha)
 
     def weibullvariate(self, alpha, beta):
         """Weibull distribution.
diff --git a/Misc/NEWS.d/next/Library/2020-08-01-00-51-15.bpo-41421.dHKRVB.rst b/Misc/NEWS.d/next/Library/2020-08-01-00-51-15.bpo-41421.dHKRVB.rst
new file mode 100644
index 0000000000000..cf291c60d8ad5
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2020-08-01-00-51-15.bpo-41421.dHKRVB.rst
@@ -0,0 +1,3 @@
+Make an algebraic simplification to random.paretovariate().  It now is
+slightly less subject to round-off error and is slightly faster. Inputs that
+used to cause ZeroDivisionError now cause an OverflowError instead.



More information about the Python-checkins mailing list