我想在VBA中使用Weibull和广义pareto分布生成随机数。你能帮帮我吗?我对使用Analysis Toolpack-VBA不感兴趣。
提前致谢, Skeihani
答案 0 :(得分:0)
这些用户定义的函数可以执行您想要的操作:
Function RandWeib(fScale As Single, _
fShape As Single, _
Optional bVolatile As Boolean = False) As Single
' shg 2008
' http://en.wikipedia.org/wiki/Weibull_distribution
' Returns a random variate with Weibull distribution
' fScale > 0
' fShape > 0
' By formula: =Scale * -LN(RAND()) ^ (1 / Shape)
If bVolatile Then Application.Volatile
RandWeib = fScale * (-Log(1! - Rnd())) ^ (1! / fShape)
End Function
Function RandPareto(fScale As Single, _
fShape As Single, _
Optional bVolatile As Boolean = False) As Single
' shg 2015
' https://en.wikipedia.org/wiki/Pareto_distribution
' Returns a random variate with Pareto distribution
' fScale > 0
' fShape > 0
' By formula: =Scale / RAND() ^ (1 / Shape)
If bVolatile Then Application.Volatile
RandPareto = fScale / (1! - Rnd()) ^ (1! / fShape)
End Function