title: How does rand() work in C?
body: <p>I know rand() generates a random number. I have found <a href="http://www.tutorialspoint.com/c_standard_library/c_function_rand.htm" rel="nofollow">this example</a> about it:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  int main()
  {
     int i, n;
     time_t t;
  
     n = 5;
  
     /* Intializes random number generator */
     srand((unsigned) time(&amp;t));
  
     /* Print 5 random numbers from 0 to 49 */
     for( i = 0 ; i &lt; n ; i++ ) 
     {
        printf("%d\n", rand() % 50);
     }
  
     return(0);
  }
  </code></pre>
  
  <p>I know this question might sound a bit silly, but can anyone please explain how the code above works?</p>