cpython: 407625051c45 (original) (raw)

--- a/Lib/random.py +++ b/Lib/random.py @@ -432,22 +432,20 @@ class Random(_random.Random): if kappa <= 1e-6: return TWOPI * random()

while 1: u1 = random()

-

-

--- a/Lib/test/test_random.py +++ b/Lib/test/test_random.py @@ -473,6 +473,7 @@ class TestDistributions(unittest.TestCas g.random = x[:].pop; g.paretovariate(1.0) g.random = x[:].pop; g.expovariate(1.0) g.random = x[:].pop; g.weibullvariate(1.0, 1.0)

@@ -493,6 +494,7 @@ class TestDistributions(unittest.TestCas (g.uniform, (1.0,10.0), (10.0+1.0)/2, (10.0-1.0)2/12), (g.triangular, (0.0, 1.0, 1.0/3.0), 4.0/9.0, 7.0/9.0/18.0), (g.expovariate, (1.5,), 1/1.5, 1/1.52),

@@ -509,8 +511,30 @@ class TestDistributions(unittest.TestCas s1 += e s2 += (e - mu) ** 2 N = len(y)

+

def test_von_mises_range(self): # Issue 17149: von mises variates were not consistently in the @@ -526,6 +550,12 @@ class TestDistributions(unittest.TestCas msg=("vonmisesvariate({}, {}) produced a result {} out" " of range [0, 2*pi]").format(mu, kappa, sample))

+ + class TestModule(unittest.TestCase): def testMagicConstants(self): self.assertAlmostEqual(random.NV_MAGICCONST, 1.71552776992141)

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -250,6 +250,8 @@ Core and Builtins Library ------- +- Issue #17141: random.vonmisesvariate() no more hangs for large kappas. +