title: Random Number Generator with Modulo
body: <p>I tried a small experiment with C++ random number generator code. I will post the code for everyone to see.</p>
  
  <pre><code>unsigned int array[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  unsigned int rand_seed = 4567;
  int loop = 0;
  
   srandom(rand_seed);
   while (loop &lt; 2147483647)
   {
       array[random() % 10]++;
       loop++;
   }
  
   for (int i = 0; i &lt; 10; i++)
   {
       cout &lt;&lt; array[i] &lt;&lt; endl;
   }
  </code></pre>
  
  <p>It's a simple code, not much to explain here. I learned that modulo operation causes a small bais, in this case the occurrence of 0 should be higher than other values since, 0 itself is counted and whenever 10 occurs. But when I display the contents of my <code>array</code>, the values are almost the same for all number between 0 and 9 (inclusive).  </p>
  
  <p>Can anyone let me know that this bias thing actually is correct or not? If yes that modulo operation does introduce bias, why can't I see it?  </p>
  
  <p>In math terms, can I say that my random variable X can have definite values between 0 and 9 (inclusive) and by ploting the frequency values (essentially <code>array</code> values), the resultant graph is a probability density function.  </p>
  
  <p>Just to make the question complete here is the result what I get in my <code>array</code>.</p>
  
  <p>214765115<br>
  214745521<br>
  214749449<br>
  214749304<br>
  214747088<br>
  214733986<br>
  214745858<br>
  214743477<br>
  214760340<br>
  214743509  </p>