cpython: 6a3d18cede49 (original) (raw)
Mercurial > cpython
changeset 82129:6a3d18cede49 2.7
Issue #17149: Fix random.vonmisesvariate to always return results in [0, 2*math.pi]. [#17149]
Mark Dickinson dickinsm@gmail.com | |
---|---|
date | Sun, 10 Feb 2013 14:13:40 +0000 |
parents | 010b455de0e0 |
children | 0f9113e1b541 |
files | Lib/random.py Lib/test/test_random.py Misc/NEWS |
diffstat | 3 files changed, 19 insertions(+), 2 deletions(-)[+] [-] Lib/random.py 4 Lib/test/test_random.py 14 Misc/NEWS 3 |
line wrap: on
line diff
--- a/Lib/random.py +++ b/Lib/random.py @@ -475,9 +475,9 @@ class Random(_random.Random): u3 = random() if u3 > 0.5:
theta = (mu % TWOPI) + _acos(f)[](#l1.7)
theta = (mu + _acos(f)) % TWOPI[](#l1.8) else:[](#l1.9)
theta = (mu % TWOPI) - _acos(f)[](#l1.10)
theta = (mu - _acos(f)) % TWOPI[](#l1.11)
--- a/Lib/test/test_random.py +++ b/Lib/test/test_random.py @@ -533,6 +533,20 @@ class TestDistributions(unittest.TestCas self.assertAlmostEqual(s1/N, mu, 2) self.assertAlmostEqual(s2/(N-1), sigmasqrd, 2)
- def test_von_mises_range(self):
# Issue 17149: von mises variates were not consistently in the[](#l2.8)
# range [0, 2*PI].[](#l2.9)
g = random.Random()[](#l2.10)
N = 100[](#l2.11)
for mu in 0.0, 0.1, 3.1, 6.2:[](#l2.12)
for kappa in 0.0, 2.3, 500.0:[](#l2.13)
for _ in range(N):[](#l2.14)
sample = g.vonmisesvariate(mu, kappa)[](#l2.15)
self.assertTrue([](#l2.16)
0 <= sample <= random.TWOPI,[](#l2.17)
msg=("vonmisesvariate({}, {}) produced a result {} out"[](#l2.18)
" of range [0, 2*pi]").format(mu, kappa, sample))[](#l2.19)
+ class TestModule(unittest.TestCase): def testMagicConstants(self): self.assertAlmostEqual(random.NV_MAGICCONST, 1.71552776992141)
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -202,6 +202,9 @@ Core and Builtins Library ------- +- Issue #17149: Fix random.vonmisesvariate to always return results in