Generating a bell curve arithmetically.

Started by Calin Leafshade, Wed 26/01/2011 21:36:25

Previous topic - Next topic

Calin Leafshade

How could I generate a random float (say between 0 and 100) where the distribtion follows a bell curve.

i.e how can I generate a random number where its more likely to fall near the centre of the distribution than anywhere else?

ddq

http://en.wikipedia.org/wiki/Normal_distribution

You'd need to use its probability density function, which is
Code: ags
1 / sqrt(2*pi*sigma^2) * e^(-(x-mu)^2/(2*sigma^2))

where mu is the mean and sigma^2 is the variance. I'm sure you'll have no trouble doing this in AGS script.

Misj'

This link: http://www.agner.org/random/ may be useful. Look at the Non-uniform random number generators in C++, en open the package. Near the bottom of the stoc1.cpp file you'll find the (GPL licensed) code for both the normal distribution and the truncated normal distribution. Also, the process is explained in the accompanied PDF files (search for 'normal') if you're just interested in how to do it rather than the specific code.


SMF spam blocked by CleanTalk