Uniform Random Variable Moment Let $X$ be a uniformly distributed random variable on the interval [0, 1].
What is $E[X^2]$?
How to apply the moment generating formula (if applicable?)
 A: For some random variable $X \sim \mathrm{Uniform}(a,b)$. The moment generating function is:
$$
M_X(t) =
\begin{cases}
\frac{\mathrm{e}^{bt}-\mathrm{e}^{at}}{t(b-a)} \quad  &t \ne 0 \\ 1 \quad  &t = 0
\end{cases}
$$
To tackle the problem of calculating the moments from m.g.f., one may differentiate and then take the limit as $t\rightarrow0$. See, for example, details at Wolfram Math.
A: I give two solutions.
We can first avoid using generating functions by noting that the variance of $X$ is the mean of the square minus the square of the mean - that is,
$$ V[X] = E[X^2] - E^2[X] $$
For a $(0, 1)$ uniform random variable the mean is $1/2$ and the variance is $1/12$ (check this). Rearranging this in the above relation gives that $E[X^2] = 1/3$.
Alternatively we can use the generating function, which (by searching) is
$$ M_X(t) = \frac{e^{bt} - e^{at}}{t(b-a)}, \ t \neq 0. $$
To find the $n$-th moment we take $n$ derivatives and evaluate at zero. This will yield the same answer.
A: Given that $X\sim U(0,1)$. Then,
\begin{equation*}
E(X^2)=\int_{0}^{1}x^2 f(x) dx = \int_{0}^{1}x^2  dx = \left[\dfrac{x^3}{3}\right]_{0}^{1}=\dfrac{1}{3}
\end{equation*} 
$E(X^2)$ Using MGF:
The moment generating function of the given $U(0,1)$ distribution is
\begin{eqnarray*}
M_{X}(t)&=& \int_{0}^{1}e^{tx} f(x) dx = \int_{0}^{1}e^{tx}  dx = \left[\dfrac{e^{tx}}{t}\right]_{0}^{1}=\dfrac{e^t}{t}-\dfrac{1}{t}=\dfrac{1}{t}(e^t-1),\qquad t\neq 0.\\
&=&\dfrac{1}{t}\left(1+t + \dfrac{t^2}{2!} + \dfrac{t^3}{3!} + \cdots -1\right)=\dfrac{1}{t}\left(t + \dfrac{t^2}{2!} + \dfrac{t^3}{3!} + \cdots \right)\\
&=&\left(1+ \dfrac{t}{2!} + \dfrac{t^2}{3!} + \cdots \right)\\
E(X^2)&=&M_{X}^{(2)}(0)=\dfrac{2}{3!}=\dfrac{1}{3}
\end{eqnarray*}
