Pattern: PSample
Pick multiple random elements from values
, weighted by optional weights
,
without replacement. Each return value is a list.
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 = PSample([1, 2, 3], count=2, weights=[1, 2, 3])
>>> p.nextn(16)
[[3, 2], [2, 3], [3, 2], [3, 1], [2, 3], [3, 2], [2, 3], [3, 1], [3, 2], [3, 2], [2, 3],
[3, 2], [2, 1], [2, 3], [3, 2], [2, 3]]