[SciPy-user] Generate random samples from a non-standard distribution
Fri Oct 19 03:02:41 CDT 2007
On 19/10/2007, Manu Hack <email@example.com> wrote:
> I've been goolging around but not sure how to generate random samples
> given the density function of a random variable. I was looking around
> something like scipy.stats.rv_continuous but couldn't find anything
There's always the everything-looks-like-a-nail approach: you can
implement the CDF by numerical integration of the PDF. You can
implement the inverse CDF by root-finding on the CDF. You can generate
points by generating uniform random variates and running them through
the inverse CDF.
More reasonably, you can generate a lot of samples and produce a
spline that approximates the inverse CDF, which you can then evaluate
This isn't terribly *good*, mind you, the deviations from your
distribution may be rather peculiar, but it's better than nothing.
More information about the SciPy-user