I want to sample random numbers from a given continuous distribution. Probably acceptance rejection is the best approach, but a friend of mine came up with the following idea. I think this will work for discrete distributions but is too crude for continuous densities, but I wanted to ask someone how is really good at random number generation so this is why I post this here.
Consider you have a continuous density $f$ e.q. the density of the normaldistribution. Now create $N$ points $x_1 , ... , x_N$ on the x axis and evaluate $f$ at these points: $f(x_1),..., f(x_N)$. Now multiply each of the evaluated points with $M$ (where $M$ is an integer big enough such that $M*f(x_k) \geq 1 \ \ \forall k$) and write the corresponding $x$ values $f(x)*M$ times in an array. Let´s take the standardnormaldistribution for an example: Let one of the $x_1 , ... , x_N$ be equal to zero, e.g. $x_i=0$ and choose $M=1000$. So $f(0)*M \approx 0.4*1000 = 400 $. Now write the $0 \ 400$ times in your array. Proceed like that with all the other points $x_1 , ... , x_N$ . If you now choose some indices of the array randomly (uniform) you should get normally distributed random numbers.
So what do you say to this approach?
Suppose you have a random number generator capable of picking any real number between $0$ and $1$, say it is a function called $rand()$. Let $F$ be the cumulative distribution function for the probability density function $f$. Then you can simply call $$F^{-1}(rand()),$$
in order to generate the elements of your array.