When trying to find how to simulate rolling a variable amount of dice with a variable but unique number of sides, I read that the mean is $\dfrac{sides+1}{2}$, and that the standard deviation is $\sqrt{\dfrac{quantity\times(sides^2-1)}{12}}$.
I doubt that the $12$ comes from the formula because it seems strongly linked with the examples of using two six-sided dice.
Is the formula for the standard deviation correct? If not what is it?
$\endgroup$ 33 Answers
$\begingroup$Note that
$$Var[X] = E[X^2] - E[X]^2 = \sum_{k=0}^n k^2 \cdot P(X=k) - \left [ \sum_{k=0}^n k \cdot P(X=k) \right ]^2$$
For a single $s$-sided die, that implies:
$$Var[X] = \frac{1}{s}\left(1^2 + 2^2 + 3^2 + ... s^2\right) - \left(\frac{1}{s}(1 + 2 + 3 + ... + s)\right)^2$$
This simplifies to
$$Var[X] = \frac{1}{s} \cdot \frac{s(s+1)(2s+1)}{6} - \left(\frac{1}{s} \cdot\frac{s(s+1)}{2}\right)^2$$
or
$$Var[X] = \frac{s^2 - 1}{12}$$
So the $12$ is just part of the equation. It comes from the fact that the sum of squares equation has denominator $6$, and the sum of consecutive integers equation has denominator $2$ (which gets squared to $4$). And $\text{lcm}(6, 4) = 12$.
$\endgroup$ 1 $\begingroup$$X$ is a random variable that represents our $n$ sided die.
Frequence distibution $f(x) = \begin {cases} \frac 1n & x\in \mathbb N, 1\le x \le n\\ 0 & \text {otherwise} \end {cases}$
The mean of a n sided die $E[X] =\frac 1n \sum_\limits{i=1}^n i = \frac 12 (n+1)$
the variance
$E[X^2] - E[X]^2 = \frac 1n \sum_\limits{i=1}^n i^2 - \frac 14 (n+1)^2\\
\frac 16 (2n+1)(n+1) - \frac 14 (n+1)^2\\
\frac 1{12} (n^2-1)$
the $\frac 1{12}$ is intrinsic to the math
$\endgroup$ 1 $\begingroup$The formula is correct. The 12 comes from $$\sum_{k=1}^n \frac1{n} \left(k - \frac{n+1}2\right)^2 = \frac1{12} (n^2-1) $$ Where $\frac{n+1}2$ is the mean and k goes over the possible outcomes (result of a roll can be from 1 to number of faces, $n$), each with probability $\frac1{n}$. This formula is the definition of variance for one single roll.
$\endgroup$