-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathran_method.py
More file actions
52 lines (44 loc) · 1.29 KB
/
Copy pathran_method.py
File metadata and controls
52 lines (44 loc) · 1.29 KB
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
# coding=utf-8
import random
import time
import verify as vy
N = 10
T = 90
rate = 99.0
global CHOICES
sampling_num = 10000
def main():
start = time.time()
global CHOICES
CHOICES = []
for x in range(N):
for y in range(T):
CHOICES.append([x, y])
verify_num = [0] * N
round_num = 0
value = 0.0
try:
filename = str(int(round(time.time() * 1000))) + ".log"
f = open(filename, "w")
while round_num < 50:
round_num += 1
ran = random.randint(0, len(CHOICES) - 1)
choice = CHOICES[ran]
num = 1 << (T - choice[1])
verify_num[choice[0]] |= num
CHOICES.pop(ran)
verify = vy.Verify(N, T, sampling_num)
value = verify.format_and_verify_sampling(verify_num) * 100
print("------round %d finished ---------" % round_num)
print("result: %.4f %%" % value)
print("length of CHOICES: %d" % len(CHOICES))
f.write("%.2f"%(value))
f.write("\n")
f.close()
except IOError:
print("write error")
end = time.time()
print('Running time: %s Seconds' % (end - start))
print('Average round time: %.4f Seconds' % ((end - start) / round_num))
if __name__ == '__main__':
main()