Distribution of a distance between random numbers I'm working on a problem in which I came to a question concerning distribution law of a result of operations on random variables. I will ask a simple question and hope to understand the concept from the answer to extend the idea on more common case.
Let $X$ and $Y$ be uniformly distributed on $[0,1]$ and $Z = |X-Y|$. How can we describe $Z$ then? In other words, how does its pdf look or what is $P\{Z \leq d\}$ equal to?
Thanks in advance for your answers.
 A: Obviously, $0\leqslant Z\leqslant1$ almost surely. For every $z$ in $(0,1)$, the event $[Z\geqslant z]$ corresponds to $(X,Y)$ being in a specific subset of the square $(0,1)\times(0,1)$, namely, $(X,Y)$ is either in the triangle with vertices $(0,z)$, $(1-z,1)$ and $(0,1)$, or in the triangle which is symmetrical with respect to the first diagonal. 
$\qquad\qquad\qquad\qquad$
The area of each of these triangles is $\frac12(1-z)^2$ and the area of the full square is $1$ hence $$P(Z\gt z)=2\cdot\tfrac12(1-z)^2=(1-z)^2.$$ The PDF $f_Z$ follows, as $$f_Z(z)=2(1-z)\,\mathbf 1_{0\leqslant z\leqslant1}.$$ Likewise, the PDF $f_T$ of $T=X-Y$ is given by $$f_T(t)=(1-|t|)\,\mathbf 1_{-1\leqslant t\leqslant1}.$$
A: $-Y$ will be uniformly distributed in $[-1,0]$. Therefore, the probability density of function of $Z = X-Y$ will be the convolution of $X$ and $-Y$ (it will have the shape of a triangle). 
If you then apply the absolute value operator, every negative number will be sent to its positive counterpart, so the left side of the triangle will disappear, and the right side multiplied by two (you can calculate it rigorously using this). Therefore, the pdf will be a decreasing straight line, from $X = 0$ to $Z = 1$, where it will be zero, and zero elsewhere.
