title: Why are my 'randomly' generated numbers are increasing every time I run the program?
body: <p>I'm trying to get randomly generated numbers by using <code>srand()</code> and <code>rand()</code> but with no avale: every time I run the program it increases by a certain amount of numbers. But if I use a <code>for</code> statement, no pattern can be seen.</p>
  
  <p>For example, if I use the code provided below and run and close the program 10 times, the output will be:</p>
  
  <pre><code>42
  52
  72
  78
  85
  92
  12 (it has reset)
  32
  48  
  </code></pre>
  
  <p><strong>Note</strong>: one strange thing I noticed about this that when I unfocus or  minimize <code>Visual Studio</code> and close the Command Prompt, the next time I run the program the number increases by more than 20, but, if I don't unfocus or minimze <code>Visual Studio</code> the number increases by just little over 1-5. Why's that?</p>
  
  <pre><code>#include "stdafx.h"
  #include &lt;iostream&gt;
  #include &lt;cstdlib&gt;
  #include &lt;ctime&gt;
  
  using namespace std;
  
  int main()
  {
      srand (time(NULL));
  
      int random_number = rand () % 100 + 1;
      cout &lt;&lt; "Random number: " &lt;&lt; random_number &lt;&lt; endl;
  
      return 0;
  }
  </code></pre>
  
  <p>But, if I use this code:</p>
  
  <pre><code>#include "stdafx.h"
  #include &lt;iostream&gt;
  #include &lt;cstdlib&gt;
  #include &lt;ctime&gt;
  
  using namespace std;
  
  int main()
  {
      srand (time(NULL));
  
      for (int i = 0; i &lt; 10; i++) {
          int random_number = rand () % 100 + 1;
          cout &lt;&lt; "Random number: " &lt;&lt; random_number &lt;&lt; endl;
      }
  
      return  0;
  }
  </code></pre>
  
  <p>the numbers don't have a clear pattern and I get the output:</p>
  
  <pre><code>31
  10
  81
  66
  74
  14
  6
  97
  39
  23 
  </code></pre>
  
  <p>They increase and decrease randomly by random amounts. What seems to be the problem here?</p>