I've been looking for a good algorithm for selecting a random object from a list of objects with differently weighted probabilities, and have found a veritable trove of possibilities, from putting each object in an array n times, to performing a binary search on an array containing the discrete cumulative density function (CDF), to putting the CDF in buckets, and a few more confusing responses, especially courtesy of Weighted random selection from array.
But the responses all seem to focus on efficiency of making the random selection instead of the cost of building or adjusting the weights dynamically. As my application seems that it might require the weights being adjusted at runtime nearly as often as a selection is made, what would be the most efficient algorithm allowing for dynamic adjustments to the probability weights? Adding new objects to the list will probably only be done at initialization, but removal of objects could be done a bit more infrequently than merely changing the values (perhaps setting the probability to zero would suffice).
My initial impression is that using an array of CDFs is my best bet; applying the same adjustment to everything after the probability being targeted seems trivial enough, but I'm not seeing anything quite so easy for the CDF bucket, for example. Any ideas?
If anyone cares, I'm implementing this with haxe.