Pattern: PChoice
Pick a random element from values
, weighted by optional weights
.
weights
and values
must be the same length.
weights do not need to be normalised.
Arguments
values
: A list of values
weights
: An optional list of weights, of the same length as values
Example output
>>> p = PChoice([ 0, 1, 10, 11 ])
>>> p.nextn(16)
[11, 1, 0, 10, 1, 11, 1, 0, 11, 1, 11, 1, 1, 11, 11, 1]
>>> p = PChoice([ 1, 11, 111 ], [ 8, 2, 1 ])
>>> p.nextn(16)
[111, 1, 1, 111, 1, 1, 1, 1, 1, 1, 1, 11, 1, 1, 1, 1]