[Math] How to generate a continuous random variable with the density function f(x) = 0.5(1+x), where -1 <= x <= 1.

probabilitystatistics

A random number generator generated random values from the Standard Uniform distribution Uniform(0,1). Call this random variable, $U$. Starting with a random value $u$ from $U$, show all the steps necessary to generate a continuous random variable with the density function $f(x) = 0.5(1+x)$, where $-1 \le x \le 1$.

I am doing this for a practice exam so an exact answer is not as important to me as the proper solution. I honestly have no clue how to go about this problem and have tried using similar pseudo code problems for Uniform(0,1) but still haven't been able to figure this one out in particular.

Best Answer

Suppose $X$ is a random variable with that distribution on $[-1,1]$ and $Y$ is uniformly distributed on $[0,1]$. Note that for $x \in [-1,1]$ $$\mathbb{P}(X < x) = \int_{-1}^x\frac{1+s}{2}ds = \frac{(x+1)^2}{4} = \mathbb{P}(Y < \frac{(x+1)^2}{4}) = \mathbb{P}(2 \sqrt{Y} - 1 < x).$$

So $2\sqrt{Y} - 1$ has exactly the given distribution. This procedure works in principle for other distributions. However, it works so well here because

  1. the probability on the left has an explicit formula and
  2. that formula has a nice inverse.

You will not always be so lucky. For example, to generate a normally distributed random variable from a uniform one requires another smart trick.