Let $X_1, \ldots, X_n$ be independent and $\mathrm{U}(0,1)$-distributed random variables, and let $M_1=\min \left(X_1, \ldots, X_n\right)$ and $M_2=\max \left(X_1, \ldots, X_n\right)$.
It can be shown that
$f_{M_1, M_2}\left(m_1, m_2\right)=n(n-1)\left(m_2-m_1\right)^{n-2}, \quad 0 \leq m_1 \leq m_2 \leq 1$
Let $R=M_2-M_1$. The variable $R$ provides us with a measure of spread for the sample.
(a) What is the density function for $R$?
I am not sure how they arrived to the expression above, could someone tell me how they did it?
In general, if $\{X_1,\ldots, X_n\}$ is an i.i.d. sample from a continuous distribution with CDF $F$ and $X_{(i)}$ the $i^{\mathrm{th}}$ order statistic, then from $$ \{X_{(n)}\leqslant y\} = \bigcup_{i=1}^n \{X_i\leqslant y\} $$ it is immediate that $\mathbb P(X_{(n)}\leqslant y)= F(y)^n$ for $y\in\mathbb R$. Moreover, for $x<y$ we have $$ \{X_{(1)}>x,X_{(n)}\leqslant y\}=\bigcap_{i=1}^n \{x<X_i, X_i\leqslant y\} $$ and hence $$ \mathbb P(X_{(1)}>x,X_{(n)}\leqslant y) = \prod_{i=1}^n \mathbb P(x<X_i\leqslant y) = (F(y)-F(x))^n. $$ It follows from the law of total probability that $$ F_{X_{(1)},X_{(2)}}(x,y) = \mathbb P(X_{(n)}\leqslant y) - \mathbb P(X_{(1)}>x,X_{(n)}\leqslant y) = F(y)^n - (F(y)-F(x))^n. $$ Differentiating the above with respect to $x$ and $y$ yields $$ f_{X_{(1)},X_{(n)}}(x,y) = n(n-1)(F(y)-F(x))^{n-2}f(x)f(y),\ x<y, $$ with $f$ denoting the density of $X_1$. As for the density of the spread $R:=X_{(n)}-X_{(1)}$, consider that $\{X_{(n)}-X_{(1)}\leqslant t\} = \{X_{(n)}\leqslant X_{(1)}+t\}$, and so $$ f_R(t) = \int f_{X_{(1)},X_{(n)}}(s,s+t)\ \mathsf ds = n(n-1)\int(F(s+t)-F(s))^{n-2}f(s)f(s+t)\ \mathsf ds $$ (with the bounds of integration depending on the distribution).
In this case $X_1\sim\mathsf{Unif}(0,1)$ so $F(x) = x\cdot\mathsf 1_{(0,1)}(x) + \mathsf 1_{[1,\infty)}(x)$ and $f(x)= \mathsf 1_{(0,1)}(x)$. The joint density of the minimum and maximum is thus $$ f_{(X_{(1)},X_{(n)}}(x,y) = n(n-1)(y-x)^{n-2},\ 0<x<y<1 $$ and the density of the spread $$ f_R(t) = n(n-1)\int_0^{1-r} (s+t-s)^{n-2}\ \mathsf ds = n(n-1)t^{n-2}(1-t),\ 0<t<1. $$