What would be the fastest algorithm to randomly select N items from a list based on weights distribution?
问题 I have a large list of items, each item has a weight. I'd like to select N items randomly without replacement, while the items with more weight are more probable to be selected. I'm looking for the most performing idea. Performance is paramount. Any ideas? 回答1: If you want to sample items without replacement, you have lots of options. Use a weighted-choice-with-replacement algorithm to choose random indices. There are many algorithms like this. One of them is WeightedChoice , described later