-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrand.py
28 lines (23 loc) · 865 Bytes
/
rand.py
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
import random
import math
from numpy.random import Generator, MT19937, SeedSequence
class RandomNum:
def __init__(self, seed):
self.sg = SeedSequence(seed)
self.bit_generator = MT19937(self.sg)
self.rg = []
for _ in range(10):
self.rg.append(Generator(self.bit_generator))
self.bit_generator = self.bit_generator.jumped()
self.state = self.bit_generator.state['state']['key']
def uniform(self, min_num, max_num):
random_index = random.randint(0, len(self.state) - 1)
result = min_num + (max_num - min_num) * self.state[random_index] / (self.state.max() - self.state.min())
return result
def round(self, x):
c = math.ceil(x)
f = math.floor(x)
if self.uniform(0, 1) < (x - f):
return c
else:
return f