Function AléatN(ByVal ÉTyp As Double, ParamArray Moy() As Variant) As Variant
Dim TRés() As Double, N As Long, Np As Long, AléN1 As Double: Static AléN2 As Double, DéjàDonné As Boolean
If UBound(Moy) <= 0 Then
GoSub Donner: AléatN = AléN1 * ÉTyp
If UBound(Moy) = 0 Then AléatN = Moy(0) + AléatN
Else
ReDim TRés(1 To UBound(Moy) + 1) As Double
Np = 0: N = 1: Do:
GoSub Donner: TRés(N) = Moy(Np) + AléN1 * ÉTyp: If N = UBound(TRés) Then Exit Do
Np = N: N = N + 1: Loop
AléatN = TRés
End If
Exit Function
Dim AléU1 As Double, AléU2 As Double, S As Double
Donner: If DéjàDonné Then
AléN1 = AléN2: DéjàDonné = False
Else: AléU1 = Aléat * 2 - 1
Do: AléU2 = AléU1: AléU1 = Aléat * 2 - 1: S = AléU1 * AléU1 + AléU2 * AléU2: Loop Until S <= 1
S = Sqr(-2 * Log(S) / S): AléN1 = AléU1 * S: AléN2 = AléU2 * S: DéjàDonné = True: End If
Return
End Function