나는 가중 난수 생성기 this을 사용했습니다.결함있는 난수 생성기?
import random
def weighted_choice(weights):
totals = []
running_total = 0
for w in weights:
running_total += w
totals.append(running_total)
rnd = random.random() * running_total
for i, total in enumerate(totals):
if rnd < total:
return i
는 다음과 같이
# The meaning of this dict is a little confusing, so here's the explanation:
# The keys are numbers and values are weights of its occurence and values - 1
# are weights of its disoccurence. You can imagine it like biased coins
# (except for 2 which is fair coin).
probabilities = { 0 : 1.0, 1 : 1.0, 2 : 0.5, 3 : 0.45, 4 : 0.4, 5 : 0.35,
6 : 0.3, 7 : 0.25, 8 : 0.2, 9 : 0.15, 10 : 0.1
}
numberOfDeactivations = []
for number in probabilities.keys():
x = weighted_choice([probabilities[number], 1 - probabilities[number]])
if x == 0:
numberOfDeactivations.append(number)
print "chance for ", repr(numberOfDeactivations)
내가 7
, 8
, 9
, 10
결과에 꽤 자주 참조하십시오.
이것이 확률 이론에 대한 올바른 증거가 있습니까?
? 우리에게 보여줄 수있는 히스토그램이 있습니까? –
필수 : http://xkcd.com/221/ – orlp
@OliCharlesworth 중요합니다. 히스토그램은 이것을 교정하는데 충분합니까? – xralf