Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d58a0b6

Browse files
committed
merge
2 parents c738874 + 978c6ab commit d58a0b6

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

Lib/random.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,10 @@ def triangular(self, low=0.0, high=1.0, mode=None):
355355
356356
"""
357357
u = self.random()
358-
c = 0.5 if mode is None else (mode - low) / (high - low)
358+
try:
359+
c = 0.5 if mode is None else (mode - low) / (high - low)
360+
except ZeroDivisionError:
361+
return low
359362
if u > c:
360363
u = 1.0 - u
361364
c = 1.0 - c

Lib/test/test_random.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ def test_constant(self):
602602
for variate, args, expected in [
603603
(g.uniform, (10.0, 10.0), 10.0),
604604
(g.triangular, (10.0, 10.0), 10.0),
605-
#(g.triangular, (10.0, 10.0, 10.0), 10.0),
605+
(g.triangular, (10.0, 10.0, 10.0), 10.0),
606606
(g.expovariate, (float('inf'),), 0.0),
607607
(g.vonmisesvariate, (3.0, float('inf')), 3.0),
608608
(g.gauss, (10.0, 0.0), 10.0),

0 commit comments

Comments
 (0)