I have been struggling with a simple APL problem and I'd appreciate some help.
I am trying to pick a value from a set at random where the probability of selection is defined by a set of non-negative integers. In the discussion below `⎕io` is zero.
If `counts ← 2 0 1 0 3` I'd like to return a 0 with probability 1/3, 2 with probability 1/6, and 4 with probability 1/2.
My solution so far: `{(g/⍳⍴⍺)[1⍳⍨((g←⍺>0)/+\⍺)≥1+⍵]}`