Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Calin Leafshade on Wed 26/01/2011 21:36:25

Title: Generating a bell curve arithmetically.
Post by: Calin Leafshade on Wed 26/01/2011 21:36:25
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?
Title: Re: Generating a bell curve arithmetically.
Post by: ddq on Wed 26/01/2011 22:04:15
http://en.wikipedia.org/wiki/Normal_distribution (http://en.wikipedia.org/wiki/Normal_distribution)

You'd need to use its probability density function, which is
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.
Title: Re: Generating a bell curve arithmetically.
Post by: Misj' on Thu 27/01/2011 13:39:58
This link: http://www.agner.org/random/ (http://www.agner.org/random/) may be useful. Look at the Non-uniform random number generators in C++, en open the package (http://www.agner.org/random/stocc.zip). 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.