One thing you're doing (from your other thread) is using WorksheetFunction.NormInv to generate random numbers with normal distribution. That's very slow; this runs about 100 times faster:
Function RandNorm(Optional Mean As Single = 0!, _
Optional Dev As Single = 1!, _
Optional fCorrel As Single = 0!, _
Optional bVolatile As Boolean = False) As Single()
' shg 1999-1103
' Returns a pair of random deviates (Singles) with the specified
' mean, deviation, and correlation. Orders of magnitude faster than
' =NORMINV(RAND(), Mean, Dev)
' Box-Muller Polar Method
' Donald Knuth, The Art of Computer Programming,
' Vol 2, Seminumerical Algorithms, p. 117
Dim af(1 To 2) As Single
Dim x As Single
Dim y As Single
Dim w As Single
If bVolatile Then Application.Volatile
Do
x = 2! * Rnd - 1!
y = 2! * Rnd - 1!
w = x ^ 2 + y ^ 2
Loop Until w < 1!
w = Sqr((-2! * CSng(Log(w))) / w)
af(1) = Dev * x * w + Mean
af(2) = Dev * y * w + Mean
If fCorrel <> 0! Then af(2) = fCorrel * af(1) + Sqr(1! - fCorrel * fCorrel) * af(2)
RandNorm = af
End Function
Bookmarks