diff options
author | Guido van Rossum <guido@python.org> | 1997-07-10 15:14:50 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1997-07-10 15:14:50 (GMT) |
commit | d247812521c2f020093d98807da3bcc39e233581 (patch) | |
tree | 5ec162335130e5cb20e7f11d3b28051478579542 /Lib/whrandom.py | |
parent | db25f32849730915291993ece2023c1645ff73d2 (diff) | |
download | cpython-d247812521c2f020093d98807da3bcc39e233581.zip cpython-d247812521c2f020093d98807da3bcc39e233581.tar.gz cpython-d247812521c2f020093d98807da3bcc39e233581.tar.bz2 |
Two improvements suggested by Tim Peters: speed up random() since we
know Python integers are at least 32 bits long; and avoid zeros in
initial seed value.
Diffstat (limited to 'Lib/whrandom.py')
-rw-r--r-- | Lib/whrandom.py | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/Lib/whrandom.py b/Lib/whrandom.py index 8250234..bd2dcf7 100644 --- a/Lib/whrandom.py +++ b/Lib/whrandom.py @@ -54,20 +54,17 @@ class whrandom: t, x = divmod(t, 256) t, y = divmod(t, 256) t, z = divmod(t, 256) - self._seed = (x, y, z) + # Zero is a poor seed, so substitute 1 + self._seed = (x or 1, y or 1, z or 1) # # Get the next random number in the range [0.0, 1.0). # def random(self): x, y, z = self._seed # - x1, x2 = divmod(x, 177) - y1, y2 = divmod(y, 176) - z1, z2 = divmod(z, 178) - # - x = (171 * x2 - 2 * x1) % 30269 - y = (172 * y2 - 35 * y1) % 30307 - z = (170 * z2 - 63 * z1) % 30323 + x = (171 * x) % 30269 + y = (172 * y) % 30307 + z = (170 * z) % 30323 # self._seed = x, y, z # |