-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrandom_distribution.py
54 lines (38 loc) · 1.26 KB
/
random_distribution.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# Author: Jorge Batista @ Route Technologies [[email protected]]
# Random distribution tester, using Python 3.6+
# Should work on all systems
import secrets
import string
import time
from concurrent.futures import ThreadPoolExecutor
import traceback
running = True
executor = ThreadPoolExecutor(max_workers=12)
distribution = {}
sequence = string.ascii_uppercase + "9"
runs = 0
MAX = 10000000
def runner():
global runs, distribution, running
try:
while runs < MAX:
letter = secrets.choice(sequence)
distribution[letter] += 1
runs += 1
time.sleep(0.0001)
running = False
except Exception:
print(traceback.format_exc())
def main():
for key in sequence:
distribution[key] = 0
for i in range(12):
executor.submit(runner)
while running:
d = ' | '.join(['{0}: {1}'.format(key, round(dist / runs, 4)) for key, dist in distribution.items()])
print("{0} || {1}".format(runs, d))
time.sleep(1)
d = ' | '.join(['{0}: {1}'.format(key, round(dist / runs, 4)) for key, dist in distribution.items()])
print("{0} || {1}".format(runs, d))
if __name__ == '__main__':
main()