我認為這是對數正態分布?我不知道。我的 lua 在這里:
local min = 50
local max = 500
local avg = 100
local fFloat = ( RandomInt( 0, avg ) / 100 ) ^ 2 -- float between 0 and 1, squared
local iRange = max - min -- range of min-max
local fDistribution = ( ( fFloat * iRange ) min ) / 100
finalRandPerc = fDistribution * RandomInt( min, max ) / 100
它接近作業,但有時會生成稍微太大的數字。
uj5u.com熱心網友回復:
這可以通過無數種方式來完成。另一種方法是從二項式分布中生成一個數字,乘以 450 并加上 50。我會將為二項式分布找到正確引數的任務留給您。
uj5u.com熱心網友回復:
如何計算 50 到 500 之間的亂數,平均結果為 100?
您可以使用去除尾部的 4 次卡方。
這很容易計算。
local function random_50_500()
-- result is from 50 to 500
-- mean is very near to 100
local x
repeat
x = math.log(math.random()) math.log(math.random())
until x > -18
return x * -25 50
end
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/338738.html
