M
Mara Guida
"Each time I run my program, I get the same sequence of numbers back
from rand()."
The answer to question 13.17, in the c-faq is:
#include <stdlib.h>
#include <time.h>
srand((unsigned int)time((time_t *)NULL));
Are all those casts in the srand() call really needed?
Is this ok, instead, relying on implicit casts when needed?
#include <stdlib.h>
#include <time.h>
srand(time(NULL));
/* or even
srand(time(0));
*/
PS: According to the standard, does <stdlib.h> #define NULL?
from rand()."
The answer to question 13.17, in the c-faq is:
#include <stdlib.h>
#include <time.h>
srand((unsigned int)time((time_t *)NULL));
Are all those casts in the srand() call really needed?
Is this ok, instead, relying on implicit casts when needed?
#include <stdlib.h>
#include <time.h>
srand(time(NULL));
/* or even
srand(time(0));
*/
PS: According to the standard, does <stdlib.h> #define NULL?