Discrete uniform distribution (source code)

= Discrete uniform distribution
{title2=$p_X(x)=1/n\text{ for }x\in S$}
{wiki}

= Uniform distribution on a finite set
{synonym}

A <discrete uniform distribution> gives every element of a nonempty <finite set> $S$ the same <probability>. Write $n=|S|$ for its <cardinality>. A <random variable> $X$ with this law has <support of a probability distribution> $S$ and <probability mass function>
$$
p_X(x)=\mathbb P(X=x)=\begin{cases}1/n,&x\in S,\\0,&x\notin S.\end{cases}
$$
The masses sum to $n(1/n)=1$. Conversely, if all $n$ masses equal $p$, their sum is $np=1$, so necessarily $p=1/n$. Thus equal chances determine the whole law.<Random: Probability, Mathematical Statistics, Stochastic Processes by Kyle Siegrist/Discrete Uniform Distributions>[Uniform Distributions on a Finite Set: definition and mass formula]{ref}

Counting now computes an <event>'s <probability>: for any <set> $A$ of possible values,
$$
\mathbb P(X\in A)=\sum_{x\in A\cap S}\frac1n=\frac{|A\cap S|}{n}.
$$
In particular, when $A\subseteq S$, the answer is $|A|/|S|$. The <intersection> matters: values outside the <support of a probability distribution> contribute zero. This turns a <probability> question into a <combinatorics> question, provided that equal chances are justified by the model.

For an ideal fair six-sided die, $S=\{1,2,3,4,5,6\}$ and each face has <probability> $1/6$. The <event> of an <even integer> is $\{2,4,6\}$, so its <probability> is $3/6=1/2$; the <event> $X\geq5$ has <probability> $2/6=1/3$. Direct <summation> gives the <expected value> $\mathbb E X=21/6=7/2$ and the <variance> $\operatorname{Var}(X)=91/6-(7/2)^2=35/12$. The <mean> $7/2$ is a balance point between possible outcomes. These are exact consequences of stipulated fairness, rather than measured frequencies from physical dice.

\Image[/discrete-uniform-fair-die-mass-and-mean.png]
{title=An ideal fair die: six equal probability masses and a mean between the faces}

Uniformity describes <probabilities>, not distances between values. For a second constructed model, stipulate equal-chance selection from $S=\{1,2,4,8\}$. Every value has <probability> $1/4$, despite the unequal gaps $1,2,4$. Here $\mathbb P(X\geq4)=2/4=1/2$, while the <expected value> and <variance> are
$$
\mathbb E X=\frac{1+2+4+8}{4}=\frac{15}{4},\qquad
\mathbb E[X^2]=\frac{1+4+16+64}{4}=\frac{85}{4},\qquad
\operatorname{Var}(X)=\frac{85}{4}-\left(\frac{15}{4}\right)^2=\frac{115}{16}.
$$
Neither the midpoint of the extreme values, $9/2$, nor a formula using only the <cardinality> gives these moments. For a general numerical <support of a probability distribution>, use its actual values:
$$
\mu=\frac1n\sum_{x\in S}x,\qquad
\operatorname{Var}(X)=\frac1n\sum_{x\in S}(x-\mu)^2.
$$

\Image[/discrete-uniform-nonconsecutive-values-and-sampling.png]
{title=Equal chances for unequal gaps: four masses and four equal-width sampling intervals}

Choosing an item from a finite list with equal chances is a basic building block of <simple random sampling>. A <bijection> that relabels the items preserves equal <probabilities>, although changing numerical labels can change the <expected value> and <variance>. A <function> that merges labels can destroy uniformity: for the fair-die model, $Y=\min(X,3)$ has masses $1/6,1/6,4/6$ at $1,2,3$, since four faces map to three. Always count the original equally likely outcomes.

An <indicator random variable> for membership in a <set> $A\subseteq S$ has a <Bernoulli distribution> with parameter $|A|/n$; counting that <event> over $r$ <independent> repetitions gives a <binomial distribution> with parameters $r$ and $|A|/n$. Equal chances among individual values need not produce equal chances among aggregated counts.<Introduction to Probability, Statistics, and Random Processes by Hossein Pishro-Nik>[§3.1.5, indicator random variables and binomial variables as sums of independent Bernoulli variables]{ref}