import random
def bdp(n,k):
\x09 cv = []
\x09 for i in range(k):
\x09\x09 m = []
\x09\x09 for j in range(n):
\x09\x09\x09 m.append(random.randint(1,365))
\x09\x09 counter = 0
\x09\x09 for k1 in m:
\x09\x09\x09 for k2 in m:
\x09\x09\x09\x09 if k1 == k2:
\x09\x09\x09\x09\x09 counter += 1
\x09\x09 cv.append(float(counter/2)/float(n))
\x09 ss = 0
\x09 for i in cv:
\x09\x09 ss += i
return ss/float(len(cv))
亲测能用: