If your frequencies are very disparate (some values are much more likely to occur than others), then searching through the most likely results first would yield results faster, on average. To do this, you can sort the frequency list by decreasing frequency, and then search linearly through the list for your target value. In the frequency list you'd need to store n as well as frequency(n), because the index into the frequency list will no longer be equal to n once you sort the list.
Alan
In reply to Re: Biased random number selection
by ferrency
in thread Biased random number selection
by athomason
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |