import random def xi dict Ej int float x2 for in range len x2 pow Ej E

 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
import random
def xi(k: dict, Ej:int) -> float:
x2 = 0.0
for j in range(len(k)):
x2 += pow((k[j] - Ej), 2) / Ej
return x2
def our_random():
# num = 100
# m = 259200
# c = 54773
# a = 7141
# n = 0
num = 100
m = 259200
c = 54773
a = 6
n = 0
result = []
for i in range(1005):
n = (a * n + c) % m
result.append(n % num)
count = {}
print(result)
generate_table(count, result)
print("Xi^2: " + str(xi(count, 100)))
def generate_table(count, result):
for n in result:
i = int(n / 10)
if i in count:
count[i] += 1
else:
count[i] = 1
def native_random():
num = 100
result = []
for i in range(1000):
r = random.randint(0, num - 1)
result.append(r)
count = {}
generate_table(count, result)
print("Xi^2: " + str(xi(count, 100)))
def main():
print("Our random")
our_random()
print("Native random")
native_random()
if __name__ == '__main__':
main()