Generation of random number(within a limit) code overshooting the upper limit
<p>My Computer science C++ book says that to generate random numbers with a lower limit (in this case, 15)and upper limit(in this case, 50), we have to use the following code. But when I used it I got the output as 56,32,49,15. Is there a reason why the program is giving results that overshoot the upper limit or is the code wrong. </p>

<pre><code>#include &lt;iostream&gt;
#include &lt;stdlib.h&gt;

using namespace std;
int main(){
int i,rdno;
for(i=1;i&lt;5;++i){
        rdno=(rand()%50)+15;
    cout &lt;&lt;rdno&lt;&lt;endl;
}
return 0;
}
</code></pre>