GMLscripts.com

Discuss and collaborate on GML scripts
Invert

You are not logged in.

#1 2011-04-30 15:50:53

brod
Member
From: NY, United States
Registered: 2008-12-14
Posts: 9
Website

how can I use guass_random() for my purposes?

Alright so I tried to research the exact_gauss() script by looking up guass things all over the internet, but I still don't have a solid concept on how it works... I was hoping someone could explain it to me using an example, that'd be very useful. Currently, I want to make a guass random curve that varies from 0 to 360 and is mostly attracted to 180, but at the same time I want to be able to change how much the attraction to 180. (Sometimes i want the random to be very close to 180 (very tight bell curve), and other times I want it to be very far from it(closer to a regular, linear distribution) how can I do this?)

I'm sorry for posting this, but I really just have no clue how it works and I REALLY want to understand it (I have tried doing research!). Thanks for any help.

Offline

#2 2011-04-30 16:49:00

xot
Administrator
Registered: 2007-08-18
Posts: 1,239

Re: how can I use guass_random() for my purposes?

I'm not an expert, and I didn't write the script, but it seems pretty straight-forward from my brief testing.

Expand**  Usage:
**      exact_gauss(mean, deviation)
**
**  Arguments:
**      mean        mean value of the distribution
**      deviation   standard deviation of distribution
**
**  Returns:
**      a pseudo-random number with an exact Gaussian distribution

Argument mean is the value random numbers will be clustered around. In your example, mean should be 180.
Argument deviation determines how closely clustered the numbers should be. The lower the number, the less they'll deviate from 180. By varying deviation, you can control the distribution. At a deviation of 1.0, the vast majority of numbers will be within 1.0 of the mean (sorry, I haven't worked out the exact percentage). As the deviation approaches infinity, the distribution becomes more linear. Because of the way this works, it's not possible to limit the numbers returned to a certain specific range. As the deviation increases, more and more numbers will fall outside your desired limits. You can throw-out numbers outside the range and try again, but this may become impractical as the distribution becomes more linear.
pHMD5EH.png exact_gauss(180, 10) : < 1% out of range
zyKFDdi.png exact_gauss(180, 40) : < 1% out of range
vfCEvtH.png exact_gauss(180, 100) : 7% out of range
8kxXvZw.png exact_gauss(180, 1000) : 85% out of range


Not-so-great Alternatives

You might also consider using the regular random functions modulated by a gain function. It won't provide gaussian distribution (truthfully, it's not even close), but it is a bit more predictable and controllable.

Expand**  Usage:
**      gain(g,t)
**
**  Arguments:
**      g       gain, real
**      t       value, real
Expanda = 2 * m * gain(0.5, random(1));

Here, m is the mean value of the distribution, 180 in your example. Argument g is set to 0.5 which is a perfectly linear distribution. Values above 0.5 will cluster around the mean, values below 0.5 will cluster at the edges (0 and 360).
EOSbjvp.png g = 0.25
DJ3RSXB.png g = 0.50
DzomgaM.png g = 0.75
0YaQKAS.png g = 0.95

Or you might consider using the pseudo-gauss function interpolated linearly with regular random numbers.

Expanda = m + m * lerp(0.5, gauss(), random(2)-1);

Here 0.5 is the interpolation factor. As it approaches 1.0, the distribution becomes more linear. As it approaches 0.0, the distribution becomes more Gaussian. Getting the distribution to be more narrowly confined to the mean could be achieved by passing the output of gauss through a power function. Ugly solution altogether.
ObWbdoz.png t = 0.0
uRa7UIJ.png t = 0.5


Abusing forum power since 1986.

Offline

#3 2011-05-03 05:47:46

paul23
Member
Registered: 2007-10-17
Posts: 110

Re: how can I use guass_random() for my purposes?

you could use the error function to get the integral of the gaussian curve. And then feed this the random value you gained

Offline

#4 2011-05-03 16:07:54

xot
Administrator
Registered: 2007-08-18
Posts: 1,239

Re: how can I use guass_random() for my purposes?

Maybe YOU could. I didn't understand what you just said. laugh

You are talking about this? http://www.gmlscripts.com/script/erf

Could you provide some examples?


Abusing forum power since 1986.

Offline

Board footer

Powered by FluxBB