This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author rhettinger
Recipients Christian.Kleineidam, NeilGirdhar, aisaac, davin, dkorchem, madison.may, mark.dickinson, pitrou, python-dev, rhettinger, serhiy.storchaka, tim.peters, westley.martinez, xksteven
Date 2016-09-27.04:56:06
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1474952167.72.0.771872806262.issue18844@psf.upfronthosting.co.za>
In-reply-to
Content
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
History
Date User Action Args
2016-09-27 04:56:07rhettingersetrecipients: + rhettinger, tim.peters, mark.dickinson, pitrou, aisaac, westley.martinez, python-dev, serhiy.storchaka, NeilGirdhar, madison.may, dkorchem, Christian.Kleineidam, davin, xksteven
2016-09-27 04:56:07rhettingersetmessageid: <1474952167.72.0.771872806262.issue18844@psf.upfronthosting.co.za>
2016-09-27 04:56:07rhettingerlinkissue18844 messages
2016-09-27 04:56:06rhettingercreate