Issue 13355: Make random.triangular degrade gracefully when low == high.
diff --git a/Lib/random.py b/Lib/random.py
index e89fae6..3f96a37 100644
--- a/Lib/random.py
+++ b/Lib/random.py
@@ -371,7 +371,10 @@
"""
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
diff --git a/Lib/test/test_random.py b/Lib/test/test_random.py
index ba447ee..1a5a86b 100644
--- a/Lib/test/test_random.py
+++ b/Lib/test/test_random.py
@@ -541,7 +541,7 @@
for variate, args, expected in [
(g.uniform, (10.0, 10.0), 10.0),
(g.triangular, (10.0, 10.0), 10.0),
- #(g.triangular, (10.0, 10.0, 10.0), 10.0),
+ (g.triangular, (10.0, 10.0, 10.0), 10.0),
(g.expovariate, (float('inf'),), 0.0),
(g.vonmisesvariate, (3.0, float('inf')), 3.0),
(g.gauss, (10.0, 0.0), 10.0),