I'm given a smooth probability density function via its values on a reasonable fine grid. I assume that cubic spline interpolation (or cubic spline interpolation of the logarithm of the density) will be sufficient to evaluate  it at arbitrary points with high accuracy. I wonder how to generate random numbers that reproduce this distribution.My first shot was to approximate the cumulative distribution function of this distribution by a piecewise linear function $F$ (on the original grid), draw a number $r$ from $[0,1)$ uniformly at random, and take the $x$ with $F(x)=r$. However, I noticed that the accuracy of my final results is not great, and I suspect that I lose accuracy because the piecewise constant probability density of my numerical random variable doesn't approximate the real smooth probability density function well enough. What options do I have?Here are some of my ideas:Go to the library and look for a book about Monte Carlo simulation. Or try to ask an expert.Integrate the cubic spline analytically, which gives a piecewise quartic function $F$. There would still be an analytic formula for the $x$ with $F(x)=r$, but it will probably be complicated to implement and slow to evaluate. Approximate the smooth probability density function by a piecewise linear function, which gives a piecewise quadratic function $F$. The analytic formula for the $x$ with $F(x)=r$ should be simple to implement and reasonably fast to evaluate.Approximate the logarithm of the smooth probability density function by a piecewise linear function, which gives a piecewise simple analytic function $F$. The analytic formula for the $x$ with $F(x)=r$ should be simple to implement and reasonably fast to evaluate.Approximate the smooth probability density function $g$ by a piecewise constant function $f$ such that $g \leq 1.1 f$. Now use rejection sampling by first sampling $x$ via $F(x)=r_1$, and then rejecting $x$ if $g(x) < 1.1 f(x) r_2$.Approximate $F^{-1}(r)$ by a suitable piecewise analytic function. But what does suitable mean here?
How to sample numerically from an arbitrary smooth distribution?
monte carlo;probability