title: Dice Rolling Program generates the same sequence of random numbers on every run
body: <p>I wrote a program that rolls a die with a user-specified number of sides. The problem is, it's too predictable.</p>
  
  <p>I'm using the CodeBlocks IDE, and the compiler is GCC. The program compiles nicely as both debug and release builds, but no matter what build option I choose, the executable will return the same values every time it's run. I can't have this, because its intended use is as a tabletop RPG tool, and it would be relatively easy for a smart player to cheat if they knew the pattern by which the dice would roll.</p>
  
  <p>What is the easiest way to fix this problem?</p>
  
  <p>Here's the source:</p>
  
  <pre><code>#include &lt;iostream&gt;     /* for input and output */
  #include &lt;cstdlib&gt;      /* for random numbers */
  
  using namespace std;
  
  void rolldie() {
      cout &lt;&lt; "How many sides to the die?" &lt;&lt; endl &lt;&lt; "D";
      int die;
      cin &gt;&gt; die;
      int roll = rand() % die +1;
      cout &lt;&lt; endl &lt;&lt; "The die rolled " &lt;&lt; roll &lt;&lt; endl &lt;&lt; endl &lt;&lt;  "Roll another? (Y for yes, anything else for no; Capitalization counts) ";
  }
  
  int main() {
      rolldie();
      char again;
      cin &gt;&gt; again;
      while (again == 89) {
          rolldie();
          cin &gt;&gt; again;
      }
      return 0;
  }
  </code></pre>