Function myrandMRG32k3a(norm As Double, seed As Long) As Double 'double MRG32k3a () /* P. L'Ecuyer 's generator*/ 'Converted to Visual Basic - R. Scrivens, CERN, Geneva, Switzerland - 5 Feb 2004 Static s10 As Double, s11 As Double, s12 As Double Static s20 As Double, s21 As Double, s22 As Double Static a12 As Double, a13n As Double Static a21 As Double, a23n As Double Static m1 As Double, m2 As Double Dim tmpReturn As Double Dim k As Double Dim p1 As Double, p2 As Double If seed > 0 Then s10 = seed s11 = seed + 1 s12 = seed + 2 s20 = seed + 3 s21 = seed + 4 s22 = seed + 5 a12 = 1321911# a13n = -4129054# a21 = 2784761# a23n = -2188892# m1 = 4294967087# m2 = 4294944443# End If ' Component 1 p1 = (a12 * s11 + a13n * s10) k = Int(p1 / m1) p1 = p1 - (k * m1) If (p1 < 0#) Then p1 = p1 + m1 s10 = s11 s11 = s12 s12 = p1 ' Component 2 */ p2 = (a21 * s22 + a23n * s20) k = Int(p2 / m2) p2 = p2 - (k * m2) If (p2 < 0#) Then p2 = p2 + m2 s20 = s21 s21 = s22 s22 = p2 ' Combination */ If (p1 <= p2) Then tmpReturn = ((p1 - p2 + m1) * norm / m1) Else tmpReturn = ((p1 - p2) * norm / m1) End If myrandMRG32k3a = tmpReturn End Function