title: How to generate a random number in C++?
body: <p>I'm trying to make a game with dice, and I need to have random numbers in it (to simulate the sides of the die.  I know how to make it between 1 and 6).  Using</p>
  
  <pre><code>#include &lt;cstdlib&gt; 
  #include &lt;ctime&gt; 
  #include &lt;iostream&gt;
  
  using namespace std;
  
  int main() 
  { 
      srand((unsigned)time(0)); 
      int i;
      i = (rand()%6)+1; 
      cout &lt;&lt; i &lt;&lt; "\n"; 
  }
  </code></pre>
  
  <p>doesn't work very well, because when I run the program a few times, here's the output I get:</p>
  
  <pre><code>6
  1
  1
  1
  1
  1
  2
  2
  2
  2
  5
  2
  </code></pre>
  
  <p>So I want a command that will generate a <em>different</em> random number each time, not the same one 5 times in a row.  Is there a command that will do this?</p>