Difference of two independent uniform random variables (source code)

= Difference of two independent uniform random variables
{title2=$U-V\sim q(t)=(a-|t|)/a^2,\quad |t|<a$}

If $U,V$ are <independent random variables>, each with the <uniform distribution> on $[0,a]$ for $a>0$, then $T=U-V$ has the symmetric <triangular distribution>
$$
q(t)=\begin{cases}(a-|t|)/a^2,&|t|<a,\\0,&|t|\geq a.\end{cases}
$$
The <convolution of probability densities> gives $q(t)=a^{-2}\int\mathbf1_{[0,a]}(s)\mathbf1_{[0,a]}(s+t)\,ds$. The overlap of these two <intervals> has length $a-|t|$ for $|t|<a$ and is empty otherwise, proving the formula. By <linearity of expectation> and the <variance of a sum>,
$$
\mathbb E[T]=0,\qquad\operatorname{Var}(T)=a^2/6.
$$
For $0\leq b\leq a$, its upper-tail <probability> is $(a-b)^2/(2a^2)$.

A useful model for elapsed time measured from two independently truncated clock readings uses $a$ as the display resolution and $T$ as the endpoint-offset difference. Independence is essential: uniform marginal <probability distributions> alone do not imply this <triangular distribution>. For example $U=V$ gives $T=0$ with certainty. In general, with the same uniform marginals, $\operatorname{Var}(U-V)=a^2/6-2\operatorname{Cov}(U,V)$.