I need to select a random number from 0 to n, with the caveat that each number should not be selected with equally probability. I have an array (say, @freq, defined from 0..n) containing non-normalized relative frequencies of each index. In other words, the probability of selecting i should come out to be $freq[i]/$sum_over_freq.
The routine is in the middle of a very time-critical loop (I'll eventually need to port this to Fortran on a 128-proc RS/6000, in fact), so speed is the primary concern. I've coded up a few ugly ways to do this, but what I have is all too slow. @freq is approximately static throughout the critical loop, so it might be favorable to generate a lookup within the loop that encases it. Any ideas on how best to implement this?
In reply to Biased random number selection by athomason
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |