Quantcast
Channel: RGSS3 Scripts (RMVX Ace) Latest Topics
Viewing all articles
Browse latest Browse all 416

Random Gaussian Distribution

$
0
0

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!


Viewing all articles
Browse latest Browse all 416

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>