tc39-transfer / proposal-random-functions

Proposal to add a Random namespace and several additional convenience functions for using randomness.
https://tc39-transfer.github.io/proposal-random-functions/
MIT License
3 stars 1 forks source link

Weighted sampling #6

Open tabatkins opened 5 months ago

tabatkins commented 5 months ago

The Python random.choices() function defaults to selecting an item uniformly from the collection, but optionally lets you specify a list (of the same size) of weights to make a weighted sample instead. I suspect that'll be fairly useful.

(It also lets you instead specify your weights as cumulative weights; I dunno if we really need to support both. Converting one to the other is trivial.)