Skip to content

Instantly share code, notes, and snippets.

View ogregoire's full-sized avatar

Olivier Grégoire ogregoire

  • Europe
View GitHub Profile
@vyznev
vyznev / dice_roll.py
Last active January 6, 2024 22:54
A simple bare-bones dice probability calculator framework, compatible with both Python 2 and Python 3
def dice_roll(die, count = 1, select = None):
"""Generate all possible results of rolling `die` `count` times, sorting
the results (according to the order of the sides on the die) and selecting
the first `select` elements of it.
The yielded results are tuples of the form `(roll, prob)`, where `roll` is a
sorted tuple of `select` values and `prob` is the probability of the result.
The first argument can be either a custom die, i.e. a tuple of `(side, prob)`
pairs, where `prob` is the probability of rolling `side` on the die, or just