Is it good idea to pass uninitialized variable to srand?
问题 Is it good idea to pass uninitialized variable to srand instead of result of time(NULL) ? It is one #include and one function call less. Example code: #include <stdlib.h> int main(void) { { usigned seed; //uninitialized srand(seed); } //other code return 0; } instead of #include <stdlib.h> #include <time.h> int main(void) { srand(time(NULL)); //other code return 0; } 回答1: No, it isn't. Reading an uninitialized value results in undefined behavior. It can be zero, it can be semi-random — but as