title: Why does rand() return the same value using srand(time(null)) in this for loop?
body: <p>I have the following code </p>
  
  <pre><code>#include&lt;iostream&gt;
  #include "time.h"
  
  using namespace std;
  
  void printRandomNumber()
  {
      srand(time(NULL));
      cout &lt;&lt; rand() % 3;
  }
  
  int main()
  {
      for(int i=0; i&lt;=5; i++)
      {
          printRandomNumber();
      }
  system("pause");
  }
  </code></pre>
  
  <p>The output is the same number repeated six times, I would like it to print out a mix of numbers.</p>