# Generate a random variable by composition

If I want to generate a random variable with such a pdf: $f(x) = \frac{5}{12}[1+(x-1)^4], (0 \leq x \leq 2)$ by composition, what should I do?

Some of my thought is that I can first make it into $f(x) = \frac{5}{6}\frac{1}{2} + \frac{1}{6}[\frac{5}{2}(x-1)^4]$. But I'm not sure how to proceed.

Thanks!

-

## 1 Answer

HINT: You now generate Bernoulli random variable with $p=\frac{1}{6}$. If it is zero, you output uniform random variable on $(0,2)$, otherwise you output random variable with density $\frac{5}{2} (x-1)^4$, which you can generate by inversion method.

-
Got it :) Inversion method rocks. :) –  Mathematics Lover Feb 29 '12 at 20:42