lua产生正态分布随机数

基于Box–Muller实现的产生符合正态分布随机数的方法
不是很严谨,够用就行了

----正态分布随机数   期望值为0.5  范围为0~1
math.boxMullerRandom = function()
    local u = math.random()
    local v = math.random()
    local  z = math.sqrt(-2 * math.log(u)) * math.cos( 2 * math.pi * v)
    z = (z + 3) / 6
    z = math.clamp(z , 0 , 1 )
    return z
end

猜你喜欢

转载自blog.csdn.net/thrt520asd/article/details/81778654