关于产生随机数
程序代码:
# include <stdio.h> # include <stdlib.h> # include <time.h> int main ( ) { int i; srand ((unsigned)time (NULL)); for (i = 0;i < 10;i++) { //srand ((unsigned)time (NULL)); int a = rand ( ); printf ("%d ", a); } printf ("\n"); getchar ( ); return 0; }
srand ((unsigned)time (NULL));放在循环外能产生10个不同的随机数,放在循环内确是10个相同的随机数,这是为啥?