cpython: 2704e11da558 (original) (raw)
Mercurial > cpython
changeset 82132:2704e11da558
Issue #17149: merge fix from 3.3. [#17149]
Mark Dickinson dickinsm@gmail.com | |
---|---|
date | Sun, 10 Feb 2013 14:17:20 +0000 |
parents | 029011429f80(current diff)e9b4f2927412(diff) |
children | 3c41e7943769 |
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 @@ -450,9 +450,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 @@ -512,6 +512,20 @@ class TestDistributions(unittest.TestCas self.assertAlmostEqual(s1/N, mu, places=2) self.assertAlmostEqual(s2/(N-1), sigmasqrd, places=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 @@ -244,6 +244,9 @@ Core and Builtins Library ------- +- Issue #17149: Fix random.vonmisesvariate to always return results in