# Help!!!!!!!!!!!!!!

• 04-05-2002
mill1000
Help!!!!!!!!!!!!!!
*crying* is it possible to make a max number for the rand comand its going to high!!!!! *crying*
• 04-05-2002
xlnk
yes if you do this:

Code:

`rand() % 10;`
it will go from 0 to 10

if you do this:

Code:

`(rand() % 10) + 3;`
it will go from 3 to 10
• 04-05-2002
well....almost:

rand() % 10 will return numbers 0 - 9 inclusive;

and (rand % 8) + 3 will return return numbers 3 - 10 inclusive;
• 04-05-2002
mill1000
this is kinda stupid but wat does inclusive mean
and it din't work
• 04-05-2002
asdf
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
• 04-05-2002
mill1000
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
• 04-05-2002
Imperito
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.
• 04-05-2002
asdf
if you want random values in a range try the formula

Code:

`a + rand() % (b-a+1)`
where a = lower range
b = upper range

In your case a= 140, b = 160
• 04-06-2002
ErionD
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); }```