getSumProbs: Calculate the probabilities of all possible outcome sums of a...

Description Usage Arguments Value Author(s) References Examples

View source: R/dice.R

Description

For a specified number of dice with a specified number of sides per die (and dropping a specified number of dice–those with either the lowest or highest values), getSumProbs calculates the probabilities of all possible outcome sums (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.)

Usage

1
2
3
4
5
6
7
getSumProbs(ndicePerRoll, 
nsidesPerDie, 
nkept = ndicePerRoll, 
dropLowest = TRUE,
sumModifier = 0,
perDieModifier = 0,
perDieMinOfOne = TRUE)

Arguments

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 (getSumProbs'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 sum (the dice to be kept will always be those with the highest values)

dropLowest

A single logical indicating whether to drop the lowest outcome values (FALSE drops the highest values instead)

sumModifier

A single integer representing an amount to add to or subtract from the outcome sum

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)

Value

probabilities

A matrix with a row for each possible outcome sum and three columns: one that lists each sum, one for the probability of that sum, and one for the number of ways to roll that sum

average

A single number representing the expected value of the specified dice-rolling process

Author(s)

Dylan Arena

References

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

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
## Rolling four six-sided dice and keeping the three highest die rolls

getSumProbs(ndicePerRoll = 4,
            nsidesPerDie = 6,
            nkept = 3)

## Rolling five four-sided dice and adding 1 to each die roll

getSumProbs(ndicePerRoll = 5,
            nsidesPerDie = 4,
            perDieModifier = 1)

## Rolling one twenty-sided die and adding 12 to the result

getSumProbs(ndicePerRoll = 1,
            nsidesPerDie = 20,
            sumModifier = 12)

dice documentation built on May 2, 2019, 3:01 a.m.