August 26th, 2004, 6:32 am
Hi.Maybe you want to try this VBA code.Function BoxMuller() As Double' Box-Muller transformation for quasi normally distributed random numbers' Use Rnd() if you don´t have anything more appropriate, such as' Faure, Sobol, Halton, or ... algorithms. Const TwoPi = 6.28318530717959 Static Status As Variant Static Save As Double Dim X1, X2 As Double If IsEmpty(Status) = True Then Status = 0 If Status = 0 Then Status = 1 X1 = Sqr(-2 * Log(Rnd())) X2 = TwoPi * Rnd() Save = X1 * Sin(X2) BoxMuller = X1 * Cos(X2) Else Status = 0 BoxMuller = Save End IfEnd FunctionCheers Moritz