mirror of https://github.com/python/cpython
Issue 13355: Make random.triangular degrade gracefully when low == high.
This commit is contained in:
parent
a2fc99ecea
commit
978c6abced
|
@ -355,7 +355,10 @@ class Random(_random.Random):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
u = self.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:
|
if u > c:
|
||||||
u = 1.0 - u
|
u = 1.0 - u
|
||||||
c = 1.0 - c
|
c = 1.0 - c
|
||||||
|
|
|
@ -602,7 +602,7 @@ class TestDistributions(unittest.TestCase):
|
||||||
for variate, args, expected in [
|
for variate, args, expected in [
|
||||||
(g.uniform, (10.0, 10.0), 10.0),
|
(g.uniform, (10.0, 10.0), 10.0),
|
||||||
(g.triangular, (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.expovariate, (float('inf'),), 0.0),
|
||||||
(g.vonmisesvariate, (3.0, float('inf')), 3.0),
|
(g.vonmisesvariate, (3.0, float('inf')), 3.0),
|
||||||
(g.gauss, (10.0, 0.0), 10.0),
|
(g.gauss, (10.0, 0.0), 10.0),
|
||||||
|
|
|
@ -24,6 +24,9 @@ Library
|
||||||
- Issue #14710: pkgutil.find_loader() no longer raises an exception when a
|
- Issue #14710: pkgutil.find_loader() no longer raises an exception when a
|
||||||
module doesn't exist.
|
module doesn't exist.
|
||||||
|
|
||||||
|
- Issue #13355: random.triangular() no longer fails with a ZeroDivisionError
|
||||||
|
when low equals high.
|
||||||
|
|
||||||
- Issue #21538: The plistlib module now supports loading of binary plist files
|
- Issue #21538: The plistlib module now supports loading of binary plist files
|
||||||
when reference or offset size is not a power of two.
|
when reference or offset size is not a power of two.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue