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!
本贴来自国际rpgmaker官方论坛作者:Raxmo处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址:
https://forums.rpgmakerweb.com/threads/random-gaussian-distribution.71375/