]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-41421: Algebraic simplification for random.paretovariate() (GH-21695)
authorRaymond Hettinger <rhettinger@users.noreply.github.com>
Sat, 1 Aug 2020 08:18:26 +0000 (01:18 -0700)
committerGitHub <noreply@github.com>
Sat, 1 Aug 2020 08:18:26 +0000 (01:18 -0700)
Lib/random.py
Misc/NEWS.d/next/Library/2020-08-01-00-51-15.bpo-41421.dHKRVB.rst [new file with mode: 0644]

index a6454f520df0a321495b5da6f8dade6e4c44036f..37f71110403ad8bcadf4ff126a33170b0fb7e11c 100644 (file)
@@ -749,7 +749,7 @@ class Random(_random.Random):
         # 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 (file)
index 0000000..cf291c6
--- /dev/null
@@ -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.