このコードは最大ペアワイズ製品用ですが、テストしていますが、いくつかの問題が出てきました。私のランダムリストの値は常に同じですか?
import sys
import random
while True:
a=int(random.randrange(1,1000000,101))
keys =[] # keys is empety list
i=0
while i < a :
keys.append(int(random.randrange(1,10000,8)))
i=i+1
keys.sort()
print(keys[-1], keys[-2])
x=keys[-1]*keys[-2]
print("the max is ",x)
しかし、何らかの理由により、コードの出力は常に同じです。
9993 9993
the max is 99860049
9993 9993
the max is 99860049
9993 9993
the max is 99860049
9993 9993
the max is 99860049
なぜこのようなことが起こっているのか分かりませんが、説明は分かります。
EUH 'keys'は同じです同様のサンプルを使用することを検討するためにPigeonhole principle
として知られています... –