jeudi 23 avril 2015

Weighted Random Selection from a Sorted List

I have a problem in which I have a large list of items sorted by "weights". I need to be able to randomly select items from this list, but the items closer to the start (greater weights) must have a greater chance of being selected based on an "elitism" factor.

I realize that similar questions have been asked before, but the catch here is that this list will be changing over time. New values will be sorted into the list as the last item is deleted (to keep a constant sized pool of "optimized" values).

First off, what would be the most efficient way of doing the selection? Selection must happen in real time from a list anywhere from 50 to 1000 item long.

Second, what would be the best data structure to use here? I'm using C#. Thanks!

I just thought of a possible solution, but I'd like some feedback on the idea. What if I were to generate a random float value within a certain range, and then do something along the lines of squaring it? Small values would return small values, and large values would return MUCH larger values. From what I can tell, mapping this result to the length of the list should give the desired effect. Does this sound right?




Aucun commentaire:

Enregistrer un commentaire