# Random Gaussian Distribution

#### Raxmo

##### Villager
So, I've been in need of a Gausian number generator, so I made one. Took me quite a number of hours to complete, but here it is.

#===============================================================================
# Rndom Gaussian Distribution
# Created by Raxmo, 11-23-2016
# free to use for personal and comercial no credits needed, but would be nice
#===============================================================================

#===============================================================================
# usage:
# sd is the Standard Deviation (take your realistic maximum and devide by 4)
# m is the mean, this is what the average number is
#
# Example:
# randn(0.25, 1)
# This will spread floats roughly between 0, and 2,
# where 1 is the average.
#
#===============================================================================

def randn(sd,m)

y = -2 * sd * (Math.log(rand()))**(3.0/7.0)
y = y.abs

if rand() > 0.5
y *= -1
end

y += m

end

now, you might ask yourself "Why do I need this?" my quick answer is that you really don't. BUT! for those of you out there that want to model a more accurate distribution, then here you go. One thing that I would warn you about however is that there is a small chance of absurdly large outputs. An incredibly small chance of it, but it is still there. This is due to the fact that true Gaussian distribution is pretty much infinite, or more accurately, the formula for the curve has an infinite domain. if you like that, then fine, otherwise, I recommend that you cap the output.

I hope that this helps at least one other person, I do feel a little silly for making and distributing this script, but I know it'll help me, and there is a chance that it'll help someone else.

chears!

Last edited by a moderator:

### Latest Profile Posts

Create MiniMaps, Sprites for MV Enemies, & Aethereal Plane Battlebacks | RPG Maker News #74

This might be my next project. You like it?
I'm off to search the master script list for my skill issue. HOORAY! FUN!
Fun fact: Digimon is an isekai
The problem with being a perfectionist is that you are never done with something.