Sunday, May 29, 2011

Weighted Random Selection in Python

This morning I was looking for a Python implementation of weighted random selection, i.e., I have a set of weighted items and I want to randomly select one where the probability of selecting each item is proportional to its weight.  I found this blog post by Eli Bendersky which exposes a set of approaches nicely.