Combining multiple recursive vba generators

I am trying to create a combined multiple recursive number generator in VBA and store the values ​​in an array, depending on how many numbers are to be generated. When I try to run the code, I get an overflow error while calculating the first value (X (i)). The constants I used were given from the general formula of the code.

Sub CMRG()
Sheet1.Cells.Clear
Dim Z() As Double, X() As Double, Y() As Double, n As Integer, U() As Double
'number of numbers to be generated (plus 3 for inital variables)
n = 33
ReDim Z(n)
ReDim U(n)
ReDim X(n)
ReDim Y(n)
'initial numbers
X(0) = 1234
X(1) = 2345
X(2) = 3456
Y(0) = 4567
Y(1) = 5678
Y(2) = 6789
For i = 3 To n
    X(i) = (1403580 * X(i - 2) - 810728 * X(i - 3)) Mod 4294967087#
    Y(i) = (527612 * Y(i - 1) - 1370589 * X(i - 3)) Mod 4294944443#
    Z(i) = (X(i) - Y(i)) Mod 4294967087#
    If Z(i) > 0 Then
        U(i) = Z(i) / 4294967088#
    ElseIf Z(i) = 0 Then
        U(i) = 4294967087# / 4294967088#
    End If
    Cells(i - 2, 1) = U(i)
Next i
End Sub

      

Is this related to my dimensions, or am I doing something wrong in the loop?

+3


source to share





All Articles