summaryrefslogtreecommitdiffstats
path: root/Lib/random.py
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2014-05-26 00:25:27 (GMT)
committerRaymond Hettinger <python@rcn.com>2014-05-26 00:25:27 (GMT)
commit978c6abced7f129a66c39135139e60b3e0fa4e0b (patch)
tree915451c1f2268193a5160034cd41fc59a4b5d150 /Lib/random.py
parenta2fc99eceae7b3dacc1e7280cc01c3b877ce55ab (diff)
downloadcpython-978c6abced7f129a66c39135139e60b3e0fa4e0b.zip
cpython-978c6abced7f129a66c39135139e60b3e0fa4e0b.tar.gz
cpython-978c6abced7f129a66c39135139e60b3e0fa4e0b.tar.bz2
Issue 13355: Make random.triangular degrade gracefully when low == high.
Diffstat (limited to 'Lib/random.py')
-rw-r--r--Lib/random.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/Lib/random.py b/Lib/random.py
index 174e755a..4642928 100644
--- a/Lib/random.py
+++ b/Lib/random.py
@@ -355,7 +355,10 @@ class Random(_random.Random):
"""
u = self.random()
- c = 0.5 if mode is None else (mode - low) / (high - low)
+ try:
+ c = 0.5 if mode is None else (mode - low) / (high - low)
+ except ZeroDivisionError:
+ return low
if u > c:
u = 1.0 - u
c = 1.0 - c