Given a mapping between items and their required probability of occurrence, generate a million items randomly subject to the given probabilities and compare the target probability of occurrence versus the generated values.

The total of all the probabilities should equal one. (Because floating point arithmetic is involved, this is subject to rounding errors).

aleph   1/5.0
beth    1/6.0
gimel   1/7.0
daleth  1/8.0
he      1/9.0
waw     1/10.0
zayin   1/11.0
heth    1759/27720 # adjusted so that probabilities add to 1
Related task

 Random number generator (device)


dim letters$(7)
data "aleph", "beth", "gimel", "daleth", "he", "waw", "zayin", "heth"
letters$(0) = "aleph"
letters$(1) = "beth"
letters$(2) = "gimel"
letters$(3) = "daleth"
letters$(4) = "he"
letters$(5) = "waw"
letters$(6) = "zayin"
letters$(7) = "heth"
dim actual(7)
dim probs(7)
probs(0) = 1/5.0
probs(1) = 1/6.0
probs(2) = 1/7.0
probs(3) = 1/8.0
probs(4) = 1/9.0
probs(5) = 1/10.0
probs(6) = 1/11.0
probs(7) = 1759/27720
dim cumProbs(7) 
 
cumProbs(0) = probs(0)
for i = 1 to 6
    cumProbs(i) = cumProbs(i - 1) + probs(i)
next i
cumProbs(7) = 1.0
 
n = 1000000
for test = 1 to n
    r = ran(1)
    p = 0.0
    for i = 1 to arraysize(probs(),1)
        p = p + probs(i)
        if r < p then
           actual(i) = actual(i) + 1
           break
        end if
    next i
next t
 
sumActual = 0.0
tab$ = chr$(9)
print "Letter          Actual          Expected"
print "------          --------        --------"
for i = 0 to 7   
    print letters$(i), tab$,
    print actual(i)/n using "#.######",
    sumActual = sumActual + actual(i)/n
    print probs(i) using "#.######"
next i
 
print "                --------        --------"
print "                ", sumActual using "#.######", tab$, "1.000000"
end