diff options
author | Tim Peters <tim.peters@gmail.com> | 2002-05-05 20:40:00 (GMT) |
---|---|---|
committer | Tim Peters <tim.peters@gmail.com> | 2002-05-05 20:40:00 (GMT) |
commit | 46c04e140cf26d1b44935c28c6f15ea467400d22 (patch) | |
tree | 1b3adac92e00f74e196857c7289bce4f06929704 /Lib/test/test_random.py | |
parent | 2b41b0d6a70330153952477baec47ec8c2efdc18 (diff) | |
download | cpython-46c04e140cf26d1b44935c28c6f15ea467400d22.zip cpython-46c04e140cf26d1b44935c28c6f15ea467400d22.tar.gz cpython-46c04e140cf26d1b44935c28c6f15ea467400d22.tar.bz2 |
random.gauss() uses a piece of hidden state used by nothing else,
and the .seed() and .whseed() methods failed to reset it. In other
words, setting the seed didn't completely determine the sequence of
results produced by random.gauss(). It does now. Programs repeatedly
mixing calls to a seed method with calls to gauss() may see different
results now.
Bugfix candidate (random.gauss() has always been broken in this way),
despite that it may change results.
Diffstat (limited to 'Lib/test/test_random.py')
-rw-r--r-- | Lib/test/test_random.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/Lib/test/test_random.py b/Lib/test/test_random.py new file mode 100644 index 0000000..d508c9f --- /dev/null +++ b/Lib/test/test_random.py @@ -0,0 +1,19 @@ +import test_support +import random + +# Ensure that the seed() method initializes all the hidden state. In +# particular, through 2.2.1 it failed to reset a piece of state used by +# (and only by) the .gauss() method. + +for seed in 1, 12, 123, 1234, 12345, 123456, 654321: + for seeder in random.seed, random.whseed: + seeder(seed) + x1 = random.random() + y1 = random.gauss(0, 1) + + seeder(seed) + x2 = random.random() + y2 = random.gauss(0, 1) + + test_support.vereq(x1, x2) + test_support.vereq(y1, y2) |