cpython: bdd993847ad0 (original) (raw)

--- a/Lib/random.py +++ b/Lib/random.py @@ -431,22 +431,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 @@ -440,6 +440,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)

@@ -460,6 +461,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),

@@ -476,8 +478,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 @@ -493,6 +517,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 @@ -175,6 +175,8 @@ Core and Builtins Library ------- +- Issue #17141: random.vonmisesvariate() no more hangs for large kappas. +