I like to use MySQL to do quantitative analysis and statistics.
I would like to make a MySQL user-defined function of the form:
sample_gaussian(mean, stdev) that returns a single randomized
value sampled from a gaussian distribution having mean and standard
deviation of the user-entered arguments. MySQL already has a
function rand() that returns a random number, so I just need to
know some pseudocode for constraining/transforming that value
so that it falls into the right distribution.
Any suggestions?
BTW- This is my first stackoverflow question, so please forgive
me if this question is asking too much of users on this site.
In answer to my own question, here is a MySQL user-defined function that returns a single random value sampled from a Gaussian distribution with a given mean and standard deviation.
To verify that this is in fact returning a Gaussian distribution, you can generate a series of these, then plot a histogram:
If you plot that histogram in excel or graphing tool of choice, you’ll see the bell shaped normal curve.