*crying* is it possible to make a max number for the rand comand its going to high!!!!! *crying*
Printable View
*crying* is it possible to make a max number for the rand comand its going to high!!!!! *crying*
yes if you do this:
it will go from 0 to 10Code:rand() % 10;
if you do this:
it will go from 3 to 10Code:(rand() % 10) + 3;
well....almost:
rand() % 10 will return numbers 0 - 9 inclusive;
and (rand % 8) + 3 will return return numbers 3 - 10 inclusive;
this is kinda stupid but wat does inclusive mean
and it din't work
inclusive = numbers from 0 to 9 and including 0 and 9.
Why doesn't it work? Does it compile?
Did you include stdlib? I think the rand function is in ther
it din't minimize the rand cout i wanted it between 140 - 160 but it still went higher no as high but it went to about 700
Well, lets see the way you have it written.
But lets simplify it first:
Try making a for loop that sends a random number between 140 and 170 to cout, then a '\t'. Make it iterate 50 times, and post the source if it does not do what you want it to.
if you want random values in a range try the formula
where a = lower rangeCode:a + rand() % (b-a+1)
b = upper range
In your case a= 140, b = 160
Just use the random func from the FAQ.
Code:int random(int low, int high) { // my random function
srand(time(NULL));
return low + rand()%(high-low+1);
}