I am working out of Mathematical Statistics and Data Analysis by John Rice and ran into the following interesting problem I'm having trouble figuring out.

Ch 2 (#65)

How could random variables with the following density function be generated from a uniform random number generator?

$$f(x) = \frac{1 + \alpha x}{2}, \quad -1 \leq x \leq 1,\quad -1 \leq \alpha \leq 1$$

So I believe I'm suppose to use the following fact to solve the problem

Proposition D

Let U be uniform on [0, 1], and let X = $F^{-1}$(U). Then the cdf of X is F.


$$P(X \leq x) = P(F^{-1}(U) \leq x) = P(U \leq F(x)) = F(x)$$

That is, we can use uniform random variables to generate other random variables that will have cdf F

So my goal should then be to find a cdf and it's inverse then give as input to the inverse the uniform random variable. I've included my attempt.

Given $f(x) = \frac{1 + \alpha x}{2}$

$$F(X) = \int_{-1}^{x} \frac{1 + \alpha t}{2} dt \; = \; \frac{x}{2} + \frac{\alpha x}{4} + \frac{1}{2} - \frac{\alpha}{4}$$

$$4 \cdot F(X) - 2 + \alpha = 2x + \alpha x$$

$$F^{-1}(X) = \frac{4X - 2 + \alpha}{2 + \alpha}$$

So our random variable is, for example, T where

$$T = F^{-1}(U) = \frac{4U - 2 + \alpha}{2 + \alpha}$$

The answer in the back of the book is

$$X = [-1 + 2 \sqrt{1/4 - \alpha(1/2 - \alpha / 4 - U)}]/ \alpha$$

I'm not really sure where I went wrong. Any help?

  • $\begingroup$ I think I may have spotted a problem with my integration, I'll continue to try and work it out, but any other input is still welcome $\endgroup$ Jan 4, 2016 at 17:17
  • 1
    $\begingroup$ Yes, the antiderivative should have a $t^2$ term. $\endgroup$ Jan 4, 2016 at 17:19
  • $\begingroup$ Yes that was it, I worked it out. The devil's always in the details I guess $\endgroup$ Jan 4, 2016 at 17:32
  • 1
    $\begingroup$ Slips of this kind are universal. The unfortunate thing is that sometimes they lead students who understand something perfectly well to doubt their understanding. $\endgroup$ Jan 4, 2016 at 17:36
  • $\begingroup$ This is known as Inverse Transform Sampling. Its a good technique to generate random numbers from a given density, however its naive in a sense that the CDF must be calculated (which is not always possible or is too hard). The proof to why this works is here:en.wikipedia.org/wiki/Inverse_transform_sampling You should look into rejection sampling techniques to see an alternative way to generate random numbers. $\endgroup$ Jan 4, 2016 at 23:37

2 Answers 2


The cdf appears to be wrong. When $-1\leq x\leq 1$, \begin{align*} F_X(x) &= \int_{-1}^{x} \frac{1 + \alpha t}{2} dt\\ &=\int_{-1}^x \frac{1}{2}+\frac{\alpha}{2}t\,dt\\ &=\frac{1}{2}[x+1]+\frac{\alpha}{4}[x^2-1]\\ \end{align*} Other than that, your approach seems fine.

  • $\begingroup$ Thanks for your help! After completing the square I was able to solve it. I would upvote your answer, but I don't have enough reputation yet. $\endgroup$ Jan 4, 2016 at 17:33
  • $\begingroup$ @ApprenticeOfMathematics Don't worry. It was pointed out in the comments while I was writing the answer, but I didn't see it. I'm glad you got it. $\endgroup$
    – Em.
    Jan 4, 2016 at 17:37

Comment: Demonstration in R with $\alpha = .2$ of answerbook result.

 alpha = .2;  m = 10^5;  u = runif(m)
 x = (-1 + 2*sqrt(1/4 + alpha*(1/2 + alpha/4 - u)))/alpha
 hist(x, col="wheat", prob=T)
 curve((1 + alpha*x)/2, -1, 1, lwd=2, col="blue", add=T)

enter image description here

  • 1
    $\begingroup$ Very nice! It's awesome seeing simulations supporting the textbook result $\endgroup$ Jan 4, 2016 at 18:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .