[Python-checkins] python/dist/src/Lib random.py,1.26.6.4,1.26.6.5

rhettinger@users.sourceforge.net rhettinger@users.sourceforge.net
Mon, 23 Sep 2002 07:48:18 -0700


Update of /cvsroot/python/python/dist/src/Lib
In directory usw-pr-cvs1:/tmp/cvs-serv20818

Modified Files:
      Tag: release22-maint
	random.py 
Log Message:
Whitespace normalization and backport:

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.



Index: random.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/random.py,v
retrieving revision 1.26.6.4
retrieving revision 1.26.6.5
diff -C2 -d -r1.26.6.4 -r1.26.6.5
*** random.py	14 May 2002 14:07:12 -0000	1.26.6.4
--- random.py	23 Sep 2002 14:48:16 -0000	1.26.6.5
***************
*** 117,121 ****
  
          self.seed(x)
-         self.gauss_next = None
  
  ## -------------------- core generator -------------------
--- 117,120 ----
***************
*** 151,154 ****
--- 150,155 ----
          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)."""
***************
*** 239,242 ****
--- 240,245 ----
          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.
***************
*** 445,449 ****
  
          # alpha > 0, beta > 0, mean is alpha*beta, variance is alpha*beta**2
!         
          # Warning: a few older sources define the gamma distribution in terms
          # of alpha > -1.0
--- 448,452 ----
  
          # alpha > 0, beta > 0, mean is alpha*beta, variance is alpha*beta**2
! 
          # Warning: a few older sources define the gamma distribution in terms
          # of alpha > -1.0
***************
*** 461,465 ****
              bbb = alpha - LOG4
              ccc = alpha + ainv
!             
              while 1:
                  u1 = random()
--- 464,468 ----
              bbb = alpha - LOG4
              ccc = alpha + ainv
! 
              while 1:
                  u1 = random()
***************
*** 628,632 ****
      _test_generator(N, 'gammavariate(0.01, 1.0)')
      _test_generator(N, 'gammavariate(0.1, 1.0)')
!     _test_generator(N, 'gammavariate(0.1, 2.0)')    
      _test_generator(N, 'gammavariate(0.5, 1.0)')
      _test_generator(N, 'gammavariate(0.9, 1.0)')
--- 631,635 ----
      _test_generator(N, 'gammavariate(0.01, 1.0)')
      _test_generator(N, 'gammavariate(0.1, 1.0)')
!     _test_generator(N, 'gammavariate(0.1, 2.0)')
      _test_generator(N, 'gammavariate(0.5, 1.0)')
      _test_generator(N, 'gammavariate(0.9, 1.0)')