如何在VBA中获取由日志正态分布生成的随机数? 我用了
Dim upper As Double, lower As Double
' Declare 2 arrays
Dim irr(26) As Double
Dim lirr(26) As Double
' set the upper and lower band
upper = 0.125
lower = 0.02
...
lirr(i ) = WorksheetFunction.LogInv(Rand, (upper - lower), lower) + lower
但是我收到错误。
答案 0 :(得分:1)
Option Base 1
Public Function LOGINV_SAMPLE(Optional n As Integer = 1, Optional md As Variant = 1, Optional stdv As Variant = 0) As Variant
'#Execute this as array formula i.e Cnt+Shft+Enter
Dim x(), i, p As Variant
ReDim Preserve x(n)
For i = 1 To n Step 1
Randomize
p = Rnd()
x(i) = Application.LogNorm_Inv(p, stdv, md)
Next i
LOGINV_SAMPLE = Application.Transpose(x)
End Function
这很有效。