@staticmethod<EOL><INDENT>def weighted(weights):<DEDENT>
<EOL>weights = [float(w) for w in weights]<EOL>choice = random.uniform(<NUM_LIT:0>, sum(weights))<EOL>position = <NUM_LIT:0><EOL>for i, weight in enumerate(weights):<EOL><INDENT>if position + weight >= choice:<EOL><INDENT>return i<EOL><DEDENT>position += weight<EOL><DEDENT>
Return a random integer 0 <= N <= len(weights) - 1, where the weights
determine the probability of each possible integer.

Based on this StackOverflow post by Ned Batchelder:

http://stackoverflow.com/questions/3679694/a-weighted-version-of-random-choice