[Python-checkins] python/dist/src/Lib random.py,1.69,1.69.2.1

rhettinger@users.sourceforge.net rhettinger at users.sourceforge.net
Thu Sep 15 20:07:15 CEST 2005


Update of /cvsroot/python/python/dist/src/Lib
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4852

Modified Files:
      Tag: release24-maint
	random.py 
Log Message:
Sync-up with head except for 1.72 which is Py2.5 specific.

Index: random.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/random.py,v
retrieving revision 1.69
retrieving revision 1.69.2.1
diff -u -d -r1.69 -r1.69.2.1
--- random.py	27 Sep 2004 15:29:03 -0000	1.69
+++ random.py	15 Sep 2005 18:07:11 -0000	1.69.2.1
@@ -43,7 +43,6 @@
 from types import MethodType as _MethodType, BuiltinMethodType as _BuiltinMethodType
 from math import log as _log, exp as _exp, pi as _pi, e as _e
 from math import sqrt as _sqrt, acos as _acos, cos as _cos, sin as _sin
-from math import floor as _floor
 from os import urandom as _urandom
 from binascii import hexlify as _hexlify
 
@@ -346,7 +345,7 @@
         # Math Software, 3, (1977), pp257-260.
 
         random = self.random
-        while True:
+        while 1:
             u1 = random()
             u2 = 1.0 - random()
             z = NV_MAGICCONST*(u1-0.5)/u2
@@ -416,7 +415,7 @@
         b = (a - _sqrt(2.0 * a))/(2.0 * kappa)
         r = (1.0 + b * b)/(2.0 * b)
 
-        while True:
+        while 1:
             u1 = random()
 
             z = _cos(_pi * u1)
@@ -425,7 +424,7 @@
 
             u2 = random()
 
-            if not (u2 >= c * (2.0 - c) and u2 > c * _exp(1.0 - c)):
+            if u2 < c * (2.0 - c) or u2 <= c * _exp(1.0 - c):
                 break
 
         u3 = random()
@@ -463,7 +462,7 @@
             bbb = alpha - LOG4
             ccc = alpha + ainv
 
-            while True:
+            while 1:
                 u1 = random()
                 if not 1e-7 < u1 < .9999999:
                     continue
@@ -486,18 +485,19 @@
 
             # Uses ALGORITHM GS of Statistical Computing - Kennedy & Gentle
 
-            while True:
+            while 1:
                 u = random()
                 b = (_e + alpha)/_e
                 p = b*u
                 if p <= 1.0:
-                    x = pow(p, 1.0/alpha)
+                    x = p ** (1.0/alpha)
                 else:
-                    # p > 1
                     x = -_log((b-p)/alpha)
                 u1 = random()
-                if not (((p <= 1.0) and (u1 > _exp(-x))) or
-                          ((p > 1)  and  (u1 > pow(x, alpha - 1.0)))):
+                if p > 1.0:
+                    if u1 <= x ** (alpha - 1.0):
+                        break
+                elif u1 <= _exp(-x):
                     break
             return x * beta
 



More information about the Python-checkins mailing list