wchoice(objects,
frequences,
filter=True,
normalize=True)
| source code
|
wchoice(objects, frequences, filter=True, normalize=True): return a
function that return the given objects with the specified frequency
distribution. If no objects with frequency>0 are given, return a
constant function that return None.
Input: objects: sequence of elements to choose. frequences: sequence
of their frequences. filter=False disables the filtering, speeding up the
object creation, but less bad cases are controlled. Frequences must be
float > 0. normalize=False disables the probablitity normalization.
The choice becomes faster, but sum(frequences) must be 1
|