title: How to generate random numbers between 2 values, inclusive?
body: <p>I need help figuring out how to generate a set amount of random numbers between two user-inputted values, inclusively. Just so you know, I have searched for this but am not finding what I have just stated. Here is my code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;ctime&gt;
  #include &lt;cstdlib&gt;
  
  using namespace std;
  
  int main()
  {
      int userBeg, userEnd, outPut;
  
      cout &lt;&lt; "Enter a start value: ";
      cin &gt;&gt; userBeg;
      cout &lt;&lt; "Enter an end value: ";
      cin &gt;&gt; userEnd;
  
      srand(time(NULL)); //generates random seed val
  
      for (int i = 0; i &lt; 5; i++) {
        //prints number between user input, inclusive
      outPut = rand()%((userEnd - userBeg) + 1); 
      cout &lt;&lt; outPut &lt;&lt; "  ";
      }//end for
  
      return 0;
  }//end main 
  </code></pre>
  
  <p>I'm confused with the output I get for the following ranges: 
  1-100 yield output numbers which fall in-between, but not including, the boundaries such as 50, 97, 24, 59, 22.
  But, 10-20 yield numbers such as 1, 14, 6, 12, 13. Here, the output is outside of the boundaries as well as in-between them. What am I doing wrong?</p>
  
  <p>Thank you in advance for your help!</p>