random.gauss(mu, sigma)
Above is a function allowing to randomly draw a number from a normal distribution with a given mean and variance. But how can we draw values from a normal distribution defined by more than only the two first moments?
something like:
random.gauss(mu, sigma, skew, kurtosis)
How about using scipy? You can pick the distribution you want from continuous distributions in the scipy.stats library.
The generalized gamma function has non-zero skew and kurtosis, but you'll have a little work to do to figure out what parameters to use to specify the distribution to get a particular mean, variance, skew and kurtosis. Here's some code to get you started.
This displays a histogram of a 10,000 element sample from a normal distribution with mean 100 and variance 25, and prints the distribution's statistics:
(array(100.0), array(25.0), array(0.0), array(0.0))
Replacing the normal distribution with the generalized gamma distribution,
you get the statistics [mean, variance, skew, kurtosis]
(array(60.67925117494595), array(0.00023388203873597746), array(-0.09588807605341435), array(-0.028177799805207737))
.Try to use this:
http://statsmodels.sourceforge.net/devel/generated/statsmodels.sandbox.distributions.extras.pdf_mvsk.html#statsmodels.sandbox.distributions.extras.pdf_mvsk
Looks good to me. There's a link to the source on that page.
Oh, and here's the other StackOverflow question that pointed me there: Apply kurtosis to a distribution in python