Rnd()只返回数组中的一个变量

时间:2015-12-08 23:56:50

标签: vba excel-vba excel

我正在尝试创建随机sigma数组。当我调用下面的代码时,它会生成一个包含1000个相同数字的数组,请指教。

Steps = 1000
Dim ArrayRand() As Double
For i = 1 To Steps
    ReDim Preserve ArrayRand(1 To Steps)
    Randomize
    ArrayRand(i) = WorksheetFunction.NormSInv(Rnd)
Next i

1 个答案:

答案 0 :(得分:5)

步骤始终为1000

Steps = 1000
Dim ArrayRand(1 to Steps) As Double
For i = 1 To Steps
    Randomize
    ArrayRand(i) = WorksheetFunction.NormSInv(Rnd())
Next i