aboutsummaryrefslogtreecommitdiff
path: root/SyncRNG.py
diff options
context:
space:
mode:
authorGertjan van den Burg <burg@ese.eur.nl>2015-07-31 16:21:25 +0200
committerGertjan van den Burg <burg@ese.eur.nl>2015-07-31 16:21:25 +0200
commit2971238c8957df1bce0629c12d8c209b39328590 (patch)
tree5c84f9bede77ea23d6bc3467cbb82e619feb85ac /SyncRNG.py
parentmore reliable way to import SyncRNG from R (diff)
downloadSyncRNG-2971238c8957df1bce0629c12d8c209b39328590.tar.gz
SyncRNG-2971238c8957df1bce0629c12d8c209b39328590.zip
reformat to proper python and R packages
Diffstat (limited to 'SyncRNG.py')
-rw-r--r--SyncRNG.py47
1 files changed, 0 insertions, 47 deletions
diff --git a/SyncRNG.py b/SyncRNG.py
deleted file mode 100644
index 7ef6fd6..0000000
--- a/SyncRNG.py
+++ /dev/null
@@ -1,47 +0,0 @@
-"""
-Simple interface to SyncRNG. This file defines a SyncRNG object which can be
-used to seed and pull numbers from the RNG.
-
-"""
-
-from __future__ import division
-
-from warnings import warn as _warn
-
-import syncrng
-
-class SyncRNG(object):
-
- def __init__(self, seed=0):
- self.BPF = 32
- self.seed = seed
- self.state = syncrng.seed(seed)
-
- def randi(self):
- tmp = syncrng.rand(self.state)
- self.state = tmp[:-1]
- return(tmp[-1])
-
- def rand(self):
- return self.randi() * 2.3283064365387e-10
-
- def randbelow(self, n):
- maxsize = 1<<self.BPF
- if n >= maxsize:
- _warn("Underlying random generator does not supply \n"
- "enough bits to choose from a population range this "
- "large.\n")
- return int(self.rand() * n)
- rem = maxsize % n
- limit = (maxsize - rem) / maxsize
- r = self.rand()
- while r >= limit:
- r = self.rand()
- return int(r*maxsize) % n
-
- def shuffle(self, x):
- y = x[:]
- for i in reversed(range(1, len(y))):
- j = self.randbelow(i+1)
- y[i], y[j] = y[j], y[i]
- return y