Code:
int GetRandomValues(int nTimes, int low, int high)
{
if(nTimes)
{
int i = 0;
int randomNumber = 0;
int width = high - low + 1;
if(width < 0)
width = -width;
//Initialise generator.
srand(time(NULL));
for(i = 0; i < nTimes; randomNumber = (rand() % width) + low, printf("Random Number Generated: %d\n", randomNumber), i++);
if(i == nTimes)
return 0;
else
{
printf("Error in loop.\n");
return -1;
}
}
else
{
printf("Please insure that we have a non zero number of times.\n");
return -2;
}
}
The above code generates nTimes the numbers you want. Check it and make one for yourself. If you encounted any problems tell us.
In main() call the fucntion like that:
GetRandomValues(10, 1,2);
Happy Codings.