in reply to Re: Biased random number selection
in thread Biased random number selection
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.My gut says that the cost of sorting will far outweigh the cost of finding your desired item, unless you could cache the result of the sort so it's done once, not once per operation.
My gut has been known to be wrong before though. {grin}
-- Randal L. Schwartz, Perl hacker
|
|---|