-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathseedcacherandom.py
More file actions
31 lines (29 loc) · 998 Bytes
/
seedcacherandom.py
File metadata and controls
31 lines (29 loc) · 998 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
coins = "HTTHTHHTHTHTHHHTHTHTHTHHTHTHTHTHTHTHHHTHHTTTHTHTHTHT"
randomcache = [x == "H" for x in coins]
import random
randomcache = [random.choice([True, False]) for x in range(len(coins))]
class RandomGenerator:
def __init__(self):
self.orgcache = [*randomcache]
self.cache = [*self.orgcache]
def _getRandomBits(self, n):
bits = [self.cache.pop(0)]
if self.cache == []: self.cache = [*self.orgcache]
if len(bits) < n:
bits += self._getRandomBits(n - len(bits))
return bits[:n]
def getRandomBits(self, n):
b = self._getRandomBits(n)
return [c for c in b]
def randint(self, a: int, b: int) -> int:
return a + self.getRandomBits(b - a).count(True)
def choice(self, seq: list) -> int:
return seq[self.randint(0, len(seq) - 1)]
def random(self) -> float:
return self.randint(0, 100000) / 100000
# precision of 1/100000
random = RandomGenerator()
if __name__ == "__main__":
d = [0 for x in range(10)]
for i in range(10000): d[random.choice(range(10))] += 1
print(d)