Home
last modified time | relevance | path

Searched refs:cum_weights (Results 1 – 3 of 3) sorted by relevance

/external/python/cpython3/Lib/
Drandom.py344 def choices(self, population, weights=None, *, cum_weights=None, k=1): argument
352 if cum_weights is None:
357 cum_weights = list(_itertools.accumulate(weights))
360 if len(cum_weights) != len(population):
363 total = cum_weights[-1]
364 hi = len(cum_weights) - 1
365 return [population[bisect(cum_weights, random() * total, 0, hi)]
/external/python/cpython3/Lib/test/
Dtest_random.py165 choices(k=5, population=data, cum_weights=range(4)),
202 … choices(data, cum_weights=[1,2], k=5) # len(weights) != len(population)
204 choices(data, cum_weights=10, k=5) # non-iterable cum_weights
206 choices(data, cum_weights=[None]*4, k=5) # non-numeric cum_weights
208 … choices(data, range(4), cum_weights=range(4), k=5) # both weights and cum_weights
214 self.assertTrue(set(choices(data, cum_weights=weights, k=5)) <= set(data))
228 choices([], cum_weights=[], k=5)
707 c = self.gen.choices(range(n), cum_weights=range(1, n+1), k=10000)
713 cum_weights = [18, 36, 38]
724 c = self.gen.choices(population, cum_weights=cum_weights, k=10000)
/external/python/cpython3/Doc/library/
Drandom.rst142 .. function:: choices(population, weights=None, *, cum_weights=None, k=1)
148 relative weights. Alternatively, if a *cum_weights* sequence is given, the
156 If neither *weights* nor *cum_weights* are specified, selections are made
159 to specify both *weights* and *cum_weights*.
161 The *weights* or *cum_weights* can use any numeric type that interoperates
389 ... return choices('HT', cum_weights=(0.60, 1.00), k=7).count('H') >= 5