title: Why is this code not randomly generating a number between 1 and 2?
body: <p>I am working on a coin toss program.  When I run this code, it returns 2, 100 times.  Why is it not randomly returning 1's and 2's?  (Thank you for helping me?</p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  
  
  using namespace std;
  
  int cointoss (){
      int toss=0;
      srand((int)time(NULL));
  
      //generating random number 1-2
      toss = rand() % 2 + 1;
      
      return(toss);
  }
    
  int main() {
      int toss = 0;
  
      for (int i=0; i&lt;100; i++)
      {
          toss = cointoss();
          cout &lt;&lt; toss &lt;&lt; endl;
      }
      return 0;
      
  }
  </code></pre>