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)


PROGRAM PROB_CHOICE
 
   DIM ITEM$[7],PROB[7],CNT[7]
 
BEGIN
   ITEM$[]=("aleph","beth","gimel","daleth","he","waw","zayin","heth")
 
   PROB[0]=1/5.0  PROB[1]=1/6.0  PROB[2]=1/7.0   PROB[3]=1/8.0
   PROB[4]=1/9.0  PROB[5]=1/10.0 PROB[6]=1/11.0  PROB[7]=1759/27720
   SUM=0
   FOR I%=0 TO UBOUND(PROB,1) DO
      SUM=SUM+PROB[I%]
   END FOR
 
   IF ABS(SUM-1)>1E-6 THEN
        PRINT("Probabilities don't sum to 1")
      ELSE
        FOR TRIAL=1 TO 1E6 DO
           R=RND(1)
           P=0
           FOR I%=0 TO UBOUND(PROB,1) DO
              P+=PROB[I%]
              IF R<P THEN
                 CNT[I%]+=1
                 EXIT
              END IF
           END FOR
        END FOR
        PRINT("Item        actual    theoretical")
        PRINT("---------------------------------")
        FOR I%=0 TO UBOUND(ITEM$,1) DO
           WRITE("\      \    #.######  #.######";ITEM$[I%],CNT[I%]/1E6,PROB[I%])
        END FOR
   END IF
END PROGRAM