title: Picking A, C and M for Linear congruential generator
body: <p>I am looking to implement a simple <a href="http://en.wikipedia.org/wiki/Pseudorandom_number_generator" rel="noreferrer">pseudorandom number generator</a> (PRNG) that has a specified period and guaranteed no collisions for the duration of that period. After doing some research I came across the very famous <a href="http://en.wikipedia.org/wiki/Linear_congruential_generator" rel="noreferrer">LCG</a> which is perfect. The problem is, I am having trouble understanding how to properly configure it. Here is my current implementation:</p>
  
  <pre><code>    function LCG (state)
      {
          var a = ?;
          var c = ?;
          var m = ?;
  
          return (a * state + c) % m;
      }
  </code></pre>
  
  <p>It says that in order to have a full period for all seed values the following conditions must be met:</p>
  
  <ol>
  <li><strong>c</strong> and <strong>m</strong> are relatively prime</li>
  <li><strong>a-1</strong> is divisible by all prime factors of <strong>m</strong></li>
  <li><strong>a-1</strong> is a multiple of 4 if <strong>m</strong> is a multiple of 4</li>
  </ol>
  
  <p><strong>1</strong> and <strong>3</strong> are simple to understand and test for. However what about <strong>2</strong>, I don't quite understand what that means or how to check for it. And what about C, can it be zero? what if it's non-zero?</p>
  
  <p><em>Overall I need to select A, C and M in such a way that I have a period of <strong>48^5 - 1</strong>. M is equal to the period, I am not sure about A and C.</em></p>