I am using acceptance-rejection sampling to sample random variable $x$ according to distribution $f(x)$. The steps I followed are
- First generated uniformly distributed random variable $x$ from 0 to $x_{max}$
- Generated a second random number $u$ between 0 and $f_{max}$.
- Then checked the condition if $u < f(x)$, If this condition is satisfied then I accept $x$ otherwise reject and repeat the above two steps.
In the 1st step I have generated $x$ that follows a uniform distribution. Is it possible to sample random variable $x$ that already has distribution which is not uniform ? Means $x$ already has a distribution function $g(x)$ but I want to sample those $x$ who will follow my desired distribution function $f(x)$.
Example: The initial random variable $x$ has a distribution function as shown in the figure (which is not uniform).
My target distribution looks like the figure below.
Now Is it possible to sample $x$ from the first figure that will follow the target distribution function (second figure)? If yes, then how to do this? Should I use any other method than acceptance-rejection sampling.