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)


  [ $ "bigrat.qky" loadfile ] now!
 
( --------------- zen object orientation -------------- )
 
  [ immovable
    ]this[ swap do ]done[ ]     is object     ( [ -->   )
 
  [ ]'[ ]                       is method     (   --> [ )
 
  [ method
      [ dup share
        swap put ] ]            is localise   (   -->   )
 
  [ method [ release ] ]        is delocalise (   -->   )
 
 
( ------------------ rand-gen methods ----------------- )
 
  [ method
      [ dup take
        2 split drop
        ' [ 0 0 ] join
        swap put ] ]            is reset-gen  (   --> [ )
 
  [ method
      [ dup take
        dup 2 peek 1+
        swap 2 poke
        dup 1 peek random
        over 0 peek <
        if
          [ dup 3 peek 1+
            swap 3 poke ]
      swap put ] ]              is rand-gen   (   --> [ )
 
  [ method
      [ dup echo say ": "
        share
        dup 2 peek dup echo
        say " trials" cr
        say "    Actual: "
        over 3 peek
        swap 10 point$ echo$ cr
        say "  Expected: "
        dup 0 peek
        swap 1 peek
        10 point$ echo$ cr
        cr ] ]                  is report     (   --> [ )
 
 
( ------------------ rand-gen objects ----------------- )
 
  [ object [    1     5 0 0 ] ] is aleph    (   [ -->   )
  [ object [    1     6 0 0 ] ] is beth     (   [ -->   )
  [ object [    1     7 0 0 ] ] is gimel    (   [ -->   )
  [ object [    1     8 0 0 ] ] is daleth   (   [ -->   )
  [ object [    1     9 0 0 ] ] is he       (   [ -->   )
  [ object [    1    10 0 0 ] ] is waw      (   [ -->   )
  [ object [    1    11 0 0 ] ] is zayin    (   [ -->   )
  [ object [ 1759 27720 0 0 ] ] is heth     (   [ -->   )
 
 
 ' [ aleph beth gimel daleth he waw zayin heth ]
 
  dup witheach [ reset-gen swap do ]
 
  dup witheach
    [ 1000000 times
        [ rand-gen over do ]
      drop ]
 
  witheach [ report swap do ]