Raymond Hettinger added the comment: Equidistributed examples: choices(c.execute('SELECT name FROM Employees').fetchall(), k=20) choices(['hearts', 'diamonds', 'spades', 'clubs'], k=5) choices(list(product(card_facevalues, suits)), k=5)
Weighted selection examples: Counter(choices(['red', 'black', 'green'], [18, 18, 2], k=3800)) # american roulette Counter(choices(['hit', 'miss'], [5, 1], k=600)) # russian roulette choices(fetch('employees'), fetch('years_of_service'), k=100) # tenure weighted choices(cohort, map(cancer_risk, map(risk_factors, cohort)), k=50) # risk weighted Star unpacking example: transpose = lambda s: zip(*s) craps = [(2, 1), (3, 2), (4, 3), (5, 4), (6, 5), (7, 6), (8, 5), (9, 4), (10, 3), (11, 2), (12, 1)] print(choices(*transpose(craps), k=10)) Comparative APIs from other languages: http://www.mathworks.com/help/stats/randsample.html http://docs.scipy.org/doc/numpy/reference/generated/numpy.random.choice.html https://stat.ethz.ch/R-manual/R-devel/library/base/html/sample.html https://reference.wolfram.com/language/ref/RandomChoice.html ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue18844> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com