cpython: 1062c66e9bdc (original) (raw)

--- a/Lib/random.py +++ b/Lib/random.py @@ -367,6 +367,16 @@ class Random(_random.Random): http://en.wikipedia.org/wiki/Triangular_distribution[](#l1.4) """

+

+ u = self.random() c = 0.5 if mode is None else (mode - low) / (high - low) if u > c:

--- a/Lib/test/test_random.py +++ b/Lib/test/test_random.py @@ -43,6 +43,33 @@ class TestBasicOps(unittest.TestCase): self.assertRaises(TypeError, self.gen.seed, 1, 2) self.assertRaises(TypeError, type(self.gen), [])

+

+ def test_jumpahead(self): self.gen.seed() state1 = self.gen.getstate() @@ -543,7 +570,7 @@ class TestDistributions(unittest.TestCas for variate, args, expected in [ (g.uniform, (10.0, 10.0), 10.0), (g.triangular, (10.0, 10.0), 10.0),

--- a/Misc/ACKS +++ b/Misc/ACKS @@ -907,6 +907,7 @@ Nick Seidenman Žiga Seilnach Yury Selivanov Fred Sells +Yuriy Senko Jiwon Seo Joakim Sernbrant Roger Serwy

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -22,6 +22,9 @@ Core and Builtins Library ------- +- Issue #13355: Raise ValueError on random.triangular call with invalid params.