# Generate Random Variable Using Acceptance Rejection Method

I have a question about acceptance rejection method and really appreciate your advice:

Suppose we want to generate random variable that has probability density function $$f(x)$$, since we're using acceptance-rejection method, we need another probability density function $$g(x)$$ and constant $$M$$ such that $$f(x)/g(x)<=M$$.

Our first step is: generate random variable $$y$$ from $$g(y)$$ and a random variable $$v$$ from standard uniform distribution $$[0,1]$$

Here is my doubt: is there one to one mapping between generated random variable $$y$$ and $$v$$? In other words, are they independent OR for each $$y$$, it is derived by cumulative distribution function $$G^{-1}(v)$$, be aware that we use $$v$$ in the following step

Our second step is: if $$v<={f(x)}/{(M*g(X))}$$, accept $$x=y$$

The point is that $$y$$ is derived from your easily sampled distribution $$g$$ randomly. Now you have a random test (via $$v$$) that decides whether to accept $$y$$ or not as part of the random sample of the harder to sample $$f$$.
The procedure uses $$M$$ in the accept-reject method and whilst you can derive conservative estimates with $$M$$ quite high the number of rejected samples will be very high and so sampling will take a long time. Otherwise you can do some prior analysis to determine a supposed optimal underlying $$g$$ and low value of $$M$$ that will still generate a random sample with the distribution of $$f$$ but the number of rejected samples will be minimised.