aboutsummaryrefslogtreecommitdiff
path: root/lib/whrandom.py
diff options
context:
space:
mode:
authorSkip Montanaro <[email protected]>2021-02-16 20:14:16 -0600
committerSkip Montanaro <[email protected]>2021-02-16 20:14:16 -0600
commitc2587c76f1b416cdbecb979e54941933246bf856 (patch)
treebb61ee9128075ce22af4eafa232f13c2e5a07896 /lib/whrandom.py
parentd90761a005b24018ae237bf551515772a1de656f (diff)
downloadpython-0.9.1-patched-QoL-c2587c76f1b416cdbecb979e54941933246bf856.tar.xz
python-0.9.1-patched-QoL-c2587c76f1b416cdbecb979e54941933246bf856.zip
starting over
Diffstat (limited to 'lib/whrandom.py')
-rw-r--r--lib/whrandom.py82
1 files changed, 41 insertions, 41 deletions
diff --git a/lib/whrandom.py b/lib/whrandom.py
index ee8dc67..2ce5f8f 100644
--- a/lib/whrandom.py
+++ b/lib/whrandom.py
@@ -1,29 +1,29 @@
-# WICHMANN-HILL RANDOM NUMBER GENERATOR
+# WICHMANN-HILL RANDOM NUMBER GENERATOR
#
-# Wichmann, B. A. & Hill, I. D. (1982)
-# Algorithm AS 183:
-# An efficient and portable pseudo-random number generator
-# Applied Statistics 31 (1982) 188-190
+# Wichmann, B. A. & Hill, I. D. (1982)
+# Algorithm AS 183:
+# An efficient and portable pseudo-random number generator
+# Applied Statistics 31 (1982) 188-190
#
-# see also:
-# Correction to Algorithm AS 183
-# Applied Statistics 33 (1984) 123
+# see also:
+# Correction to Algorithm AS 183
+# Applied Statistics 33 (1984) 123
#
-# McLeod, A. I. (1985)
-# A remark on Algorithm AS 183
-# Applied Statistics 34 (1985),198-200
+# McLeod, A. I. (1985)
+# A remark on Algorithm AS 183
+# Applied Statistics 34 (1985),198-200
#
#
-# USE:
-# whrandom.random() yields double precision random numbers
-# uniformly distributed between 0 and 1.
+# USE:
+# whrandom.random() yields double precision random numbers
+# uniformly distributed between 0 and 1.
#
-# whrandom.seed() must be called before whrandom.random()
-# to seed the generator
+# whrandom.seed() must be called before whrandom.random()
+# to seed the generator
-# Translated by Guido van Rossum from C source provided by
-# Adrian Baddeley.
+# Translated by Guido van Rossum from C source provided by
+# Adrian Baddeley.
# The seed
@@ -34,39 +34,39 @@ _seed = [0, 0, 0]
# Set the seed
#
def seed(x, y, z):
- _seed[:] = [x, y, z]
+ _seed[:] = [x, y, z]
# Return the next random number in the range [0.0 .. 1.0)
#
def random():
- from math import floor # floor() function
- #
- [x, y, z] = _seed
- x = 171 * (x % 177) - 2 * (x/177)
- y = 172 * (y % 176) - 35 * (y/176)
- z = 170 * (z % 178) - 63 * (z/178)
- #
- if x < 0: x = x + 30269
- if y < 0: y = y + 30307
- if z < 0: z = z + 30323
- #
- _seed[:] = [x, y, z]
- #
- term = float(x)/30269.0 + float(y)/30307.0 + float(z)/30323.0
- rand = term - floor(term)
- #
- if rand >= 1.0: rand = 0.0 # floor() inaccuracy?
- #
- return rand
+ from math import floor # floor() function
+ #
+ [x, y, z] = _seed
+ x = 171 * (x % 177) - 2 * (x/177)
+ y = 172 * (y % 176) - 35 * (y/176)
+ z = 170 * (z % 178) - 63 * (z/178)
+ #
+ if x < 0: x = x + 30269
+ if y < 0: y = y + 30307
+ if z < 0: z = z + 30323
+ #
+ _seed[:] = [x, y, z]
+ #
+ term = float(x)/30269.0 + float(y)/30307.0 + float(z)/30323.0
+ rand = term - floor(term)
+ #
+ if rand >= 1.0: rand = 0.0 # floor() inaccuracy?
+ #
+ return rand
# Initialize from the current time
#
def init():
- import time
- t = time.time()
- seed(t%256, t/256%256, t/65536%256)
+ import time
+ t = time.time()
+ seed(t%256, t/256%256, t/65536%256)
# Make sure the generator is preset to a nonzero value