diff options
| author | Gertjan van den Burg <gertjanvandenburg@gmail.com> | 2021-01-14 17:23:56 +0000 |
|---|---|---|
| committer | Gertjan van den Burg <gertjanvandenburg@gmail.com> | 2021-01-14 17:23:56 +0000 |
| commit | d49bf79e4b79b3bb3d9031c7fba4c21efc431548 (patch) | |
| tree | 5d2b35944af343f15ecb7dbd3e74f91a95ca2c3f /Python | |
| parent | Update README (diff) | |
| parent | bump roxygen (diff) | |
| download | SyncRNG-d49bf79e4b79b3bb3d9031c7fba4c21efc431548.tar.gz SyncRNG-d49bf79e4b79b3bb3d9031c7fba4c21efc431548.zip | |
Merge branch 'R'
# Conflicts:
# .gitignore
# README.md
# new_R/src/syncrng.c
Diffstat (limited to 'Python')
| -rw-r--r-- | Python/SyncRNG.py | 48 |
1 files changed, 0 insertions, 48 deletions
diff --git a/Python/SyncRNG.py b/Python/SyncRNG.py deleted file mode 100644 index 0ab4c06..0000000 --- a/Python/SyncRNG.py +++ /dev/null @@ -1,48 +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 copy import deepcopy -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 = deepcopy(x) - for i in reversed(range(1, len(y))): - j = self.randbelow(i+1) - y[i], y[j] = y[j], y[i] - return y |
