Random Gaussian Distribution

Raxmo

Villager
Member
Joined
Oct 31, 2015
Messages
7
Reaction score
1
First Language
English
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:

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??

Forum statistics

Threads
105,860
Messages
1,017,040
Members
137,569
Latest member
Shtelsky
Top