Why is Python random lib really fast for the first 10M calls [closed]
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 14 hours ago.
Improve this questionI have this script that I run:
import random
import sys
import time
start = time.time()
random_to_choose = [i for i in range(0, 100)]
counter = {i: 0 for i in random_to_choose}
def run_sims():
cnt = int(sys.argv[1]) ** 6
while cnt != 0:
counter[random.choice(random_to_choose)] += 1
cnt -= 1
print(counter)
run_sims()
print(开发者_运维知识库time.time()-start)
Result:
python .\random_check.py 10
0.32193899154663086
___________________
python .\random_check.py 20
20.77259874343872
If the 10M calls complete in 0.3s I would expect 20M to complete in around 0.6s, not 20s.
精彩评论