title: C program crashes with use of a random variable
body: <p>I want to populate a grid with 1s and 0s.
  My program crashes due to the random variable r. It works perfectly fine with a constant(eg: say r=8). I have used <code>srand(time(NULL));</code></p>
  
  <pre><code>void initGrid(int grid[GRID_HEIGHT][GRID_WIDTH])
  {
      int i,j,r;
      for(i=0;i&lt;GRID_HEIGHT;i++)
      {
          r = rand()%10;
          for(j=0;j&lt;GRID_WIDTH;j++)
          {
  
              grid[i][j]= (i*j+i+j)%(r)&lt;=2?1:0;
          }
      }
  }
  </code></pre>