Skip to content

Weighted choice #76

@frederikcreemers

Description

@frederikcreemers

I think it would be useful to have a weighted version of random.choice(), that you could call like this:

random.weightedChoice([
  ["oneSixth", 1],
  ["oneThird", 2],
  ["oneHalf", 3]
]);

And it'd add up all the weights, and for each item, its probability of being returned is the ratio of its weight over the total weight.

If you're ok with adding this, I'd be happy to send in a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions