St · Statistics & Probability

What Is the MGF of a Uniform Distribution?

Updated 13 October 2026

At a glance

  1. 1. Identify the interval

    For a continuous uniform variable, write its support as [a,b], where a is less than b.

  2. 2. Use the density

    Substitute the constant density 1/(b-a) into the expectation of exp(tX).

  3. 3. Evaluate the integral

    Integrate exp(tx) from a to b, then use the limit at t=0.

  4. 4. Differentiate for moments

    The first derivative at zero gives the mean; the second derivative gives the second moment.

For a continuous uniform random variable, the moment-generating function depends on the endpoints of its interval. If XX is uniform on [a,b][a,b], its MGF has a simple exponential form for nonzero tt and equals 1 at t=0t=0. The formula also gives the mean and variance by differentiation.

Formula for a continuous uniform distribution

Let X∼Uniform⁡(a,b)X\sim\operatorname{Uniform}(a,b), with a<ba<b. Its density is fX(x)=1/(b−a)f_X(x)=1/(b-a) for a≤x≤ba\le x\le b and zero elsewhere. By definition, the moment-generating function is

MX(t)=E[etX].M_X(t)=\mathbb{E}[e^{tX}].

Therefore,

MX(t)={ebt−eatt(b−a),t≠0,1,t=0.M_X(t)=\begin{cases} \dfrac{e^{bt}-e^{at}}{t(b-a)}, & t\ne 0,\\[6pt] 1, & t=0. \end{cases}

The MGF exists for every real value of tt. This is true because XX is bounded, so the expectation of etXe^{tX} is finite for any fixed real tt.

Deriving the formula

Use the density to express the expectation as an integral:

MX(t)=∫−∞∞etxfX(x) dx=1b−a∫abetx dx.\begin{aligned} M_X(t)&=\int_{-\infty}^{\infty}e^{tx}f_X(x)\,dx\\ &=\frac{1}{b-a}\int_a^b e^{tx}\,dx. \end{aligned}

For t≠0t\ne 0, an antiderivative of etxe^{tx} is etx/te^{tx}/t. Evaluating at the endpoints gives

MX(t)=1b−a[etxt]ab=ebt−eatt(b−a).M_X(t)=\frac{1}{b-a}\left[\frac{e^{tx}}{t}\right]_a^b =\frac{e^{bt}-e^{at}}{t(b-a)}.

At t=0t=0, the integrand in the expectation is e0X=1e^{0X}=1, so MX(0)=E[1]=1M_X(0)=\mathbb{E}[1]=1. The nonzero-tt expression also approaches 1 as tt approaches zero, but writing the value separately avoids an apparent division by zero.

Getting the mean and variance

When the MGF exists around zero, its derivatives at zero give the moments:

E[X]=MX′(0),E[X2]=MX′′(0).\mathbb{E}[X]=M_X'(0),\qquad \mathbb{E}[X^2]=M_X''(0).

For X∼Uniform⁡(a,b)X\sim\operatorname{Uniform}(a,b), these yield

E[X]=a+b2,Var⁡(X)=(b−a)212.\mathbb{E}[X]=\frac{a+b}{2},\qquad \operatorname{Var}(X)=\frac{(b-a)^2}{12}.

The variance follows from Var⁡(X)=MX′′(0)−[MX′(0)]2\operatorname{Var}(X)=M_X''(0)-[M_X'(0)]^2. The MGF is useful for more than moments: for independent random variables, the MGF of their sum is the product of their MGFs, whenever the MGFs exist.

Worked example: uniform on [2,5]

Suppose X∼Uniform⁡(2,5)X\sim\operatorname{Uniform}(2,5). Here a=2a=2 and b=5b=5, so

MX(t)={e5t−e2t3t,t≠0,1,t=0.M_X(t)=\begin{cases} \dfrac{e^{5t}-e^{2t}}{3t}, & t\ne 0,\\[6pt] 1, & t=0. \end{cases}

Expanding the exponentials near zero makes the moments visible:

MX(t)=1+72t+132t2+⋯ .M_X(t)=1+\frac{7}{2}t+\frac{13}{2}t^2+\cdots.

An MGF expansion has the form 1+E[X]t+E[X2]t2/2+⋯1+\mathbb{E}[X]t+\mathbb{E}[X^2]t^2/2+\cdots. Thus E[X]=7/2=3.5\mathbb{E}[X]=7/2=3.5 and E[X2]=13\mathbb{E}[X^2]=13. The variance is

Var⁡(X)=13−(3.5)2=0.75.\operatorname{Var}(X)=13-(3.5)^2=0.75.

This agrees with the uniform variance formula: (5−2)2/12=9/12=0.75(5-2)^2/12=9/12=0.75.

Common special cases and conventions

For the standard uniform distribution on [0,1][0,1], set a=0a=0 and b=1b=1:

MX(t)=et−1t(t≠0),MX(0)=1.M_X(t)=\frac{e^t-1}{t}\quad(t\ne0),\qquad M_X(0)=1.

For a uniform distribution on [−c,c][-c,c], where c>0c>0, the formula simplifies to MX(t)=sinh⁡(ct)/(ct)M_X(t)=\sinh(ct)/(ct) for t≠0t\ne0, with value 1 at zero.

The formula above is for a continuous uniform distribution. If instead XX is discrete and equally likely to be one of the integers a,a+1,…,ba,a+1,\ldots,b, then

MX(t)=1b−a+1∑k=abekt.M_X(t)=\frac{1}{b-a+1}\sum_{k=a}^{b}e^{kt}.

The continuous formula does not apply to that integer-valued case.

Common mistakes

  • Substituting t=0t=0 into the quotient: The quotient appears to divide by zero there. Use MX(0)=1M_X(0)=1, or take the limit.
  • Using the endpoints as the mean: The mean is their midpoint, (a+b)/2(a+b)/2, not either endpoint.
  • Confusing width and variance: The interval width is b−ab-a; the variance is its square divided by 12.
  • Forgetting the density factor: The integral must be divided by b−ab-a. Omitting it gives a result that is not an MGF, since it will not equal 1 at zero.

References

  1. A First Course in Probability — Sheldon Ross
  2. Statistical Inference — George Casella and Roger L. Berger

Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.