title: Linear Congruential Generator on VBA
body: <p>i'm trying to replicate the Linear Congruential Generator in VBA but my procedure returns to me an Error '6': Overflow...</p>
  
  <pre><code>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
  </code></pre>
  
  <p>I think the problem is in the first expression of the for cycle, in detail </p>
  
  <pre><code>a*seed
  </code></pre>
  
  <p>in the second step of the cycle.
  Any suggestion to solve the problem without splitting </p>
  
  <pre><code>a*seed
  </code></pre>
  
  <p>in </p>
  
  <pre><code>(100*seed+100*seed+100*seed+...+(a-100*n)*seed
  </code></pre>