From 1cd9a69e51453e51e53c8472017044305e11b4ce Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Fri, 31 Jul 2020 01:55:53 -0700 Subject: [PATCH 1/2] bpo-41421: Algebraic simplification for random.paretovariate() --- Lib/random.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/random.py b/Lib/random.py index a6454f520df0a3..37f71110403ad8 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. From abed64a34ad143d5faeb4c740aced36dadc09d66 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Sat, 1 Aug 2020 00:51:30 -0700 Subject: [PATCH 2/2] Add blurb --- .../next/Library/2020-08-01-00-51-15.bpo-41421.dHKRVB.rst | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2020-08-01-00-51-15.bpo-41421.dHKRVB.rst 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 00000000000000..cf291c60d8ad57 --- /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.