roll.Rd
Density, distribution function, quantile function, and random generation for the discrete distribution described by a roll expression. See below for more details.
droll(x, roll) proll(q, roll, lower.tail = TRUE) qroll(p, roll, lower.tail = TRUE) rroll(n, roll)
x | A numeric vector of outcomes. |
---|---|
roll | A roll expression (e.g., |
q | A numeric vector of outcomes. |
lower.tail | Whether to calculate |
p | A numeric vector of probabilities. |
n | Number of random deviates to return. |
The main algorithm for calculating dice probabilities comes from MathWorld.
Symbolic calculations are handled by Ryacas, and, by extension, by Yacas.
A numeric vector.
Given a roll expression (i.e., an arithmetic expression involving dice),
r()
calculates the complete distribution of the outcomes. This is possible
because the distribution is discrete and has a finite number of outcomes.
From this distribution, droll()
returns the density, proll()
returns the
distribution function, qroll()
returns the quantile function, and
rroll()
generates random deviates. They mirror functions from the
Distributions family.
For more details on roll expressions, see r()
and the Dice S4 class.
#> [1] 0.1666667# Distribution function of 2d6 + 5 proll(12, 2 * d6 + 5)#> [1] 0.5833333# Quantile function of 2d6 + 5 qroll(0.5, 2 * d6 + 5)#> [1] 12# Roll 2d6 + 5 (generate random deviate) rroll(1, 2 * d6 + 5)#> [1] 14