1. ## Rand() questions

does rand()%11 give me a number between 1-10?

2. No, it gives you a number 0-10.

3. And it reduces the randomness of the numbers.

4. i dont know exactly what to do, but having srand( GetTickCount() ); somewhere before it makes it random based on the time, so the chance of getting the same random number is much lower. but i dont know exactly how to do it

5. Code:
```#include <time.h>

.....

srand(time(0));```

6. It's a secret.
Don't tell anyone

7. try this...
Code:
```#include <time.h>
#include <stdlib.h>

int main (void)
{
int Numb;

srand (time (NULL));
Numb = (rand () % 10) + 1;

while (Numb > 10)
{
Numb--;
}

return 0;
}```

8. Code:
```  Posted by dsig111
Numb = (rand () % 10) + 1;

while (Numb > 10)
{
Numb--;
}```
What is that supposed to achieve?

>>rand() % 10
will give a number between 0 and 9. You then add one to it, so effectively, it's giving a number between 1 and 10.

So what's the "while" loop for?

9. I forgot got thrown off by the %11

10. thx but this code produced 9 in the begining and when another function calls the function it is in it rises to 10. any sugjestions on how to stop it from aways being nine and on how to reset it when the function ends
Code:
`int rnum=rand()%11+1;`

11. First off, did you read the two links I gave you?

>>sugjestions on how to stop it from aways being nine<<
If it's random, it'll do what it wants to. You might get any number between min and max.

>>how to reset it when the function ends<<
You can't "reset" it as such, only reset it back to the start of the psuedo random number list, but that isn't recommend.

12. the srand function sets a seed to randomize off of and when using time to do it it will set the seed different ly each time and stop using % 11 it returns 0-10 snd when add 1 it returns 1-11...

Code:
```srand (time (NULL)); //must have stdlib.h and time.h

int rnum = (rand () % 10) + 1;```
the above will produce trully random values of 1 -10.

13. also if you want to prevent it from repeating the last value use a while statement...

Code:
```#include <time.h>
#include <stdlib.h>

int main (void)
{
int rnum, p_rnum;

srand (time (NULL));
rnum = (rand () % 10) + 1;

/* later on */

do
{
srand (time (NULL));

p_rnum = rnum;
rnum = (rand () % 10) + 1);
} while (p_rnum == rnum);

return 0;
}```

14. >>srand (time (NULL)); twice
You shouldn't be calling srand() twice in the same program. This is also in the FAQ.

15. Im so confused yes i did go to the links but can some one simplify the srand and time i dont get it