i'm trying to replicate the Linear Congruential Generator in VBA but my procedure returns to me an Error '6': Overflow...
Sub test()
Dim a As Long, c As Long, period As Long
Dim seed As Long, sample As Long, max As Long
Dim i As Long
seed = 1234
sample = 2
max = 100
a = 48271
c = 0
period = 2 ^ 31 - 1
For i = 1 To sample
seed = (a * seed + c) Mod period
Next i
End Sub
I think the problem is in the first expression of the for cycle, in detail
a*seed
in the second step of the cycle. Any suggestion to solve the problem without splitting
a*seed
in
(100*seed+100*seed+100*seed+...+(a-100*n)*seed