I am trying to generate random ints from a LOW number and a HIGH number, it does seem to work, but it seems to generate the same number a few times before it moves to another number.
What might i do to improve this? Or is this the best i could do with generating random ints from start/stop?
#include <iostream>
#include <cstdlib>
#include <ctime>
usingnamespace std;
int randnum(int maxnum, int start=0, int increment=0){
/*maxnum = max number minus one
* start = number no less than accepted
* increment = add increment to
*/
int num=0;
srand(time(0));
while (true){
num = (rand() % maxnum) + increment;
if (start == 0)
return num;
elseif (num < start)
continue;
elsebreak;
}
return num;
}
int main(){
cout << randnum(11, 5) << endl;
}
PS i have been doing Python for a while and decided to get back into relearning C++.