]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Andrew Kuchling writes:
authorGuido van Rossum <guido@python.org>
Mon, 16 Feb 1998 14:52:42 +0000 (14:52 +0000)
committerGuido van Rossum <guido@python.org>
Mon, 16 Feb 1998 14:52:42 +0000 (14:52 +0000)
First, the RNG in whrandom.py sucks if you let it seed itself from the time.
The problem is the line:
t = int((t&0xffffff) | (t>>24))
Since it ORs the two parts together, the resulting value has mostly
ON bits.  Change | to ^, and you don't lose any randomness.

Lib/whrandom.py

index bd2dcf7befd8d5235dc13cdb0a9f06fe90d11e2d..95e88f3399b53683c21901fc6f8fc49e5db1886b 100644 (file)
@@ -50,7 +50,7 @@ class whrandom:
                        # Initialize from current time
                        import time
                        t = long(time.time() * 256)
-                       t = int((t&0xffffff) | (t>>24))
+                       t = int((t&0xffffff) ^ (t>>24))
                        t, x = divmod(t, 256)
                        t, y = divmod(t, 256)
                        t, z = divmod(t, 256)