getTotalProbs {dice} | R Documentation |
For a specified number of dice with a specified number of sides per die (and dropping a specified number of dice–those with the lowest values), getTotalProbs
calculates the probabilities of all possible outcome totals (i.e., all possible sums of those dice whose results are not dropped); the function also accommodates modifiers (either to each die roll or to the sum), such as rolling five four-sided dice and adding 1 to the outcome of each roll, or rolling one twenty-sided die and adding 12 to the outcome. (Such modified rolls frequently occur in the context of role-playing games, e.g., Dungeons & Dragons, Mutants & Masterminds, or BESM.)
getTotalProbs(ndicePerRoll, nsidesPerDie, nkept = ndicePerRoll, totalModifier = 0, perDieModifier = 0, perDieMinOfOne = TRUE)
ndicePerRoll |
A single positive integer representing the number of dice to roll |
nsidesPerDie |
A single positive integer representing the number of sides on each die (getTotalProbs 's dice-rolling process involves only one type of die per call) |
nkept |
A single positive integer representing the number of dice whose values to include when calculating the total (the dice to be kept will always be those with the highest values) |
totalModifier |
A single integer representing an amount to add to or subtract from the outcome total |
perDieModifier |
A single integer representing an amount to add to or subtract from each die roll |
perDieMinOfOne |
A logical flag indicating whether each die roll should be considered to have a minimum value of 1 (as is often true in role-playing game contexts) |
probabilities |
A matrix with a row for each possible outcome total and three columns: one that lists each total, one for the probability of that total, and one for the number of ways to roll that total |
average |
A single number representing the expected value of the specified dice-rolling process |
Dylan Arena
This function's implementation originated with the ideas presented in the following forum thread:
http://www.enworld.org/showthread.php?t=56352&page=1&pp=40
# ## Rolling four six-sided dice and keeping the three highest die rolls getTotalProbs(ndicePerRoll = 4, nsidesPerDie = 6, nkept = 3) ## Rolling five four-sided dice and adding 1 to each die roll getTotalProbs(ndicePerRoll = 5, nsidesPerDie = 4, perDieModifier = 1) ## Rolling one twenty-sided die and adding 12 to the result getTotalProbs(ndicePerRoll = 1, nsidesPerDie = 20, totalModifier = 12)