title: Why does the random number generator not randomize numbers in the void function but does in the main function?
body: <pre><code>#include &lt;iostream&gt;
  #include &lt;cstdlib&gt; 
  #include &lt;iomanip&gt;
  #include &lt;ctime&gt;
  using namespace std;
  
  void coinToss();
  
  int main()
  {
  
  cout &lt;&lt; &quot;How many times do you want to flip the coin?\n&quot;;
     
  int choice;
     
  cin &gt;&gt; choice;
  
     for (int i = 1 ; i &lt;= choice; i++)
     {
         cout &lt;&lt; &quot;Rolling Dice # &quot; &lt;&lt; i &lt;&lt; endl;
         coinToss();
  
     }
     return 0;
  }
  
  void coinToss()
  {
     
  unsigned seed = time(0);
     
  srand(seed);
  
     int result;
     result = (rand() % (2 - 1 + 1)) + 1;
     if (result == 2)
         cout &lt;&lt; &quot;Tails\n&quot;;
     else
         cout &lt;&lt; &quot;Heads\n&quot;;
         cout &lt;&lt; endl;
  }
  </code></pre>
  <blockquote>
  <p>When I do this it does not randomize the number and just gives the same number over and over. But if i  put &quot;unsigned see = time(0); srand(seed);&quot; in my main function it actually randomizes and gives out different numbers?</p>
  </blockquote>