Distribution of a random segment on a string I have a linear string of unit length, and I randomly sample two locations a and b from Uniform(0, 1). Then I cut the string at these two locations to get a sub-string. What is the distribution for the size of the sub-string (i.e. |a-b|)? Otherwise, I want to at least know the mean and variance.
 A: $(a,b)$ constitute one draw from the uniform distribution on the unit square. The region where $|a - b| \gt x$ is a pair of equilateral right triangles, one at $(0,1)$ and the other at $(1,0)$ with side lengths $1-x$; they fit together into a square with area $(1-x)^2$.  Thus the CDF of $x = |a-b|$ equals $1 - (1-x)^2$, $0 \le x \le 1$.

A similar analysis appears in the solution to problem 43 of Fred Mosteller's Fifty Challenging Problems in Probability (1965).  It asks for the expected values of the smallest, middle, and largest pieces.
A: Here's a snippet of Maple code that shows that the PDF of $\lvert a - b \rvert$ is $2 - 2 t$:
with(Statistics):
a := RandomVariable(Uniform(0,1));
b := RandomVariable(Uniform(0,1));
PDF(abs(X - Y), t) assuming 0 < t, t < 1;

returns $2 - 2 t$. You can see that it's true by computing the probability that $\lvert a - b \rvert < t$ by hand: it's the area of the subset of the unit square that has horizontal or vertical distance to the diagonal of at most $t$; which means that it's one minus the area of two right triangles with legs of length $1 - t$; which means that it's $1 - 2 \cdot \frac{(1 - t)^2}{2} = 1 - (1 - t)^2$. The derivative of that is $2 - 2t$.
(Disclaimer: I maintain Maple's Statistics package.)
