This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |