summaryrefslogtreecommitdiff
path: root/Lib/random.py
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2002-05-05 20:40:00 +0000
committerTim Peters <tim.peters@gmail.com>2002-05-05 20:40:00 +0000
commit827538c2ab66dd0befc428dc2a6f355fdd00f029 (patch)
tree5dc955a9b8c5c6eac5b11f20871a75a668338e1b /Lib/random.py
parentff04ba1a88019d6a5ecbd19fbfb674b5b68cfa22 (diff)
downloadcpython-827538c2ab66dd0befc428dc2a6f355fdd00f029.tar.gz
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/random.py')
-rw-r--r--Lib/random.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/Lib/random.py b/Lib/random.py
index f502d1dee7..fe25642191 100644
--- a/Lib/random.py
+++ b/Lib/random.py
@@ -116,7 +116,6 @@ class Random:
"""
self.seed(x)
- self.gauss_next = None
## -------------------- core generator -------------------
@@ -150,6 +149,8 @@ class Random:
a, z = divmod(a, 30322)
self._seed = int(x)+1, int(y)+1, int(z)+1
+ self.gauss_next = None
+
def random(self):
"""Get the next random number in the range [0.0, 1.0)."""
@@ -238,6 +239,8 @@ class Random:
# Zero is a poor seed, so substitute 1
self._seed = (x or 1, y or 1, z or 1)
+ self.gauss_next = None
+
def whseed(self, a=None):
"""Seed from hashable object's hash code.