Random Gaussian Distribution


Oct 31, 2015
Reaction score
First Language
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

y += m


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.

Last edited by a moderator:

Latest Threads

Latest Posts

Latest Profile Posts

I remember once when I was at Disney's Animal Kingdom and I got to dance with some of the cast members! It was so much fun! After the show my dad and I got frozen lemonade and some ice cream. It makes me feel better remembering the good things about my dad... maybe I will return to Orlando.
spending almost entire day to mod skyrim but it still couldn't run properly :(
My friend has become one with the glitter. @ImaginaryVillain, got any room in the Cult of the Sporkle?
I still cannot wrap my head around how to edit and use arrays in RPG Maker MV o_O
Gamemaking has been slower, but I do my best to make small progress every day. :)

Forum statistics

Latest member