随机数发生器,广义Pareto分布和VBA中的Weilbull分布

时间:2015-11-09 14:48:02

标签: excel-vba random distribution weibull vba

我想在VBA中使用Weibull和广义pareto分布生成随机数。你能帮帮我吗?我对使用Analysis Toolpack-VBA不感兴趣。

提前致谢, Skeihani

1 个答案:

答案 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