Home
last modified time | relevance | path

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

/third_party/python/Lib/
Drandom.py506 def choices(self, population, weights=None, *, cum_weights=None, k=1): argument
515 if cum_weights is None:
521 cum_weights = list(_accumulate(weights))
531 if len(cum_weights) != n:
533 total = cum_weights[-1] + 0.0 # convert to float
540 return [population[bisect(cum_weights, random() * total, 0, hi)]
/third_party/python/Lib/test/
Dtest_random.py243 choices(k=5, population=data, cum_weights=range(4)),
280 … choices(data, cum_weights=[1,2], k=5) # len(weights) != len(population)
282 choices(data, cum_weights=10, k=5) # non-iterable cum_weights
284 choices(data, cum_weights=[None]*4, k=5) # non-numeric cum_weights
286 … choices(data, range(4), cum_weights=range(4), k=5) # both weights and cum_weights
292 self.assertTrue(set(choices(data, cum_weights=weights, k=5)) <= set(data))
306 choices([], cum_weights=[], k=5)
881 c = self.gen.choices(range(n), cum_weights=range(1, n+1), k=10000)
887 cum_weights = [18, 36, 38]
898 c = self.gen.choices(population, cum_weights=cum_weights, k=10000)
/third_party/python/Doc/library/
Drandom.rst173 .. function:: choices(population, weights=None, *, cum_weights=None, k=1)
179 relative weights. Alternatively, if a *cum_weights* sequence is given, the
187 If neither *weights* nor *cum_weights* are specified, selections are made
190 to specify both *weights* and *cum_weights*.
192 The *weights* or *cum_weights* can use any numeric type that interoperates
461 ... return choices('HT', cum_weights=(0.60, 1.00), k=7).count('H') >= 5