samedi 26 janvier 2019

generating random number with normal distribution in VBA

I have problem with generating random numbers with normal distribution in VBA. I’m working on NSGAII. I use “Application.WorksheetFunction.Norm_Inv (Rnd, Mean, Deviation)” to generate rand numbers with normal distribution. But I face this error:

Runtime error ‘1004’: Unable to get the Norm_Inv property of the worksheetfunction class

How can I fix this error?

I’ve already used this code in another simple macro and it works. But by using this code in NSGAII code there is an error! (Large number of variables (double, long, Boolean, etc.) and 2D arrays are defined and used in NSGAII code and it consist of do while, for, etc. loops)

Function GenerateNormRand ()
Dim myrand As Double
randomize
myrand = Application.WorksheetFunction.Norm_Inv(Rnd, 0, 5)
GenerateNormRand = rand
End Function

Error




Aucun commentaire:

Enregistrer un commentaire