# Thread: Use srand() twice in a function?

1. ## Use srand() twice in a function?

Can I use the srand() function twice in a function like so?

Code:
```void delaycalc(void)
{
int one;
int result;

srand((unsigned)time(NULL));
one = rand();

srand(one);
result = rand() % 1200;

printf("%i", result);
}```
You see I'm trying to get random numbers that are 1200 or less. However, when I use the time function to make a seed and loop the function so it displays 20 random numbers, it increments slowly like 2390, 2394, 2398 etc.

So it's hardly random. So can I use two srand() functions to try and randomise it more (Preferably so the values move down sometimes aswell)?

2. Originally Posted by Jake.c
You see I'm trying to get random numbers that are 1200 or less. However, when I use the time function to make a seed and loop the function so it displays 20 random numbers, it increments slowly like 2390, 2394, 2398 etc.
You could... wait longer before running the program again

Prelude suggests that you hash the value returned by time(). For an example, read her article on using rand().

3. you should not use srand twice - it will descrease the randomness of your results, not increase them

4. Now I have the problem of the function that the eternally confused tutorial gives at the end. When I try to compile it says:

Code:
```unsigned readySeed()
{
time_t now = time ();
unsigned char *p = (unsigned char *)&now;
unsigned seed = 0;
size_t i;

for ( i = 0; i < sizeof now; i++ )
seed = seed * ( UCHAR_MAX + 2U ) + p[i];

return seed;
}```
`UCHAR_MAX' undeclared (first use in this function)

5. You need to #include <limits.h>

6. Oh thankyou very much!