@staticmethod<EOL><INDENT>def weighted(weights, sample_size, with_replacement=False):<DEDENT>
assert sample_size <= len(weights), "<STR_LIT>"<EOL>weights = [float(w) for w in weights]<EOL>weight_indexes = list(range(<NUM_LIT:0>, len(weights)))<EOL>samples = []<EOL>while len(samples) < sample_size:<EOL><INDENT>sample = OneOf.weighted(weights)<EOL>samples.append(weight_indexes[sample])<EOL>if not with_replacement:<EOL><INDENT>del weights[sample]<EOL>del weight_indexes[sample]<EOL><DEDENT><DEDENT>return samples<EOL>
Return a set of random integers 0 <= N <= len(weights) - 1, where the
weights determine the probability of each possible integer in the set.