-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
61 lines (45 loc) · 1.43 KB
/
main.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
55
56
57
58
59
60
61
from typing import List
from RandomNumberGenerator import RandomNumberGenerator
def main():
# Test Data, the distribution has to add up to 1.0
sample_dist = {
1: 0.2,
2: 0.05,
7: 0.25,
9: 0.1,
11: 0.4
}
print('Distribution:')
print(sample_dist)
# Arbitrary seed value (the meaning of life)
seed = 42
# Instantiate the random number generator
rng = RandomNumberGenerator(seed, sample_dist)
test_random_number_generator(rng)
def test_random_number_generator(rng):
random_numbers = []
for i in range(100_000_000):
num = rng.get_random_number()
random_numbers.append(num)
freq_map = create_frequency_map(random_numbers)
print("\nNumber of generated values: %d " % (len(random_numbers)))
print('Frequency Map')
print(freq_map)
normalized_freq_map = calculate_normalized_map(freq_map, len(random_numbers))
print('\nNormalized Frequency Map')
print(normalized_freq_map)
def create_frequency_map(numbers: List[int]):
freq_map = {}
for num in numbers:
if num in freq_map:
freq_map[num] = freq_map[num] + 1
else:
freq_map[num] = 1
return freq_map
def calculate_normalized_map(freq_map, total_numbers):
normalized_map = {}
for key in freq_map:
normalized_map[key] = freq_map[key] / total_numbers
return normalized_map
if __name__ == '__main__':
main()