summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1994-09-14 13:33:57 (GMT)
committerGuido van Rossum <guido@python.org>1994-09-14 13:33:57 (GMT)
commit14a6e3d5e8f91816f71e4bab976c61de3870a272 (patch)
treebe0a33eca53520c71f451884f709dd1d0186ac16 /Lib
parent602099a7560ab65cd3e0fde9a3defc9e2beb9d87 (diff)
downloadcpython-14a6e3d5e8f91816f71e4bab976c61de3870a272.zip
cpython-14a6e3d5e8f91816f71e4bab976c61de3870a272.tar.gz
cpython-14a6e3d5e8f91816f71e4bab976c61de3870a272.tar.bz2
* Lib/whrandom.py: if seed is (0,0,0), initialize from current
time; default seed's arguments to (0,0,0)
Diffstat (limited to 'Lib')
-rw-r--r--Lib/whrandom.py18
1 files changed, 9 insertions, 9 deletions
diff --git a/Lib/whrandom.py b/Lib/whrandom.py
index 7317b44..8ed39c9 100644
--- a/Lib/whrandom.py
+++ b/Lib/whrandom.py
@@ -35,24 +35,24 @@ class whrandom:
# Without arguments, initialize from current time.
# With arguments (x, y, z), initialize from them.
#
- def __init__(self, x = None, y = None, z = None):
- if x is None:
- # Initialize from current time
- import time
- t = int(time.time() % 0x80000000)
- t, x = divmod(t, 256)
- t, y = divmod(t, 256)
- t, z = divmod(t, 256)
+ def __init__(self, x = 0, y = 0, z = 0):
self.seed(x, y, z)
#
# Set the seed from (x, y, z).
# These must be integers in the range [0, 256).
#
- def seed(self, x, y, z):
+ def seed(self, x = 0, y = 0, z = 0):
if not type(x) == type(y) == type(z) == type(0):
raise TypeError, 'seeds must be integers'
if not 0 <= x < 256 and 0 <= y < 256 and 0 <= z < 256:
raise ValueError, 'seeds must be in range(0, 256)'
+ if 0 == x == y == z:
+ # Initialize from current time
+ import time
+ t = int(time.time() % 0x80000000)
+ t, x = divmod(t, 256)
+ t, y = divmod(t, 256)
+ t, z = divmod(t, 256)
self._seed = (x, y, z)
#
# Get the next random number in the range [0.0, 1.0).