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)


/# Rosetta Code problem: http://rosettacode.org/wiki/Probabilistic_choice
by Galileo, 05/2022 #/
 
include ..\Utilitys.pmt
 
( ( "aleph" 0.200000 0 ) ( "beth" 0.166667 0 ) ( "gimel" 0.142857 0 ) ( "daleth" 0.125000 0 )
  ( "he" 0.111111 0 ) ( "waw" 0.100000 0 ) ( "zayin" 0.090909 0 ) ( "heth" 0.063456 0 ) )
len 1 swap 2 tolist var lprob
 
1000000 var trial
 
trial for drop
    rand >ps
    0 >ps
    lprob for var i
        ( i 2 ) sget ps> + 
        tps swap dup >ps < if 
           ( i 3 ) sget 1 + ( i 3 ) sset
           exitfor
        endif
    endfor
    ps> ps> drop drop
endfor
 
( "item" "\t" "actual" "\t\t" "theoretical" ) lprint nl nl
lprob for drop
    pop swap
    1 get "\t" rot 3 get trial / "\t" rot 2 get nip "\n" 6 tolist lprint
endfor