Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 14a6e3d

Browse files
committed
* Lib/whrandom.py: if seed is (0,0,0), initialize from current
time; default seed's arguments to (0,0,0)
1 parent 602099a commit 14a6e3d

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

Lib/whrandom.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,24 +35,24 @@ class whrandom:
3535
# Without arguments, initialize from current time.
3636
# With arguments (x, y, z), initialize from them.
3737
#
38-
def __init__(self, x = None, y = None, z = None):
39-
if x is None:
40-
# Initialize from current time
41-
import time
42-
t = int(time.time() % 0x80000000)
43-
t, x = divmod(t, 256)
44-
t, y = divmod(t, 256)
45-
t, z = divmod(t, 256)
38+
def __init__(self, x = 0, y = 0, z = 0):
4639
self.seed(x, y, z)
4740
#
4841
# Set the seed from (x, y, z).
4942
# These must be integers in the range [0, 256).
5043
#
51-
def seed(self, x, y, z):
44+
def seed(self, x = 0, y = 0, z = 0):
5245
if not type(x) == type(y) == type(z) == type(0):
5346
raise TypeError, 'seeds must be integers'
5447
if not 0 <= x < 256 and 0 <= y < 256 and 0 <= z < 256:
5548
raise ValueError, 'seeds must be in range(0, 256)'
49+
if 0 == x == y == z:
50+
# Initialize from current time
51+
import time
52+
t = int(time.time() % 0x80000000)
53+
t, x = divmod(t, 256)
54+
t, y = divmod(t, 256)
55+
t, z = divmod(t, 256)
5656
self._seed = (x, y, z)
5757
#
5858
# Get the next random number in the range [0.0, 1.0).

0 commit comments

Comments
 (0)