Issue 13355: Make random.triangular degrade gracefully when low == high.

This commit is contained in:
Raymond Hettinger 2014-05-25 17:25:27 -07:00
parent a2fc99ecea
commit 978c6abced
3 changed files with 8 additions and 2 deletions

View file

@ -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