这段代码
#include
#include
#include
int main ()
{
printf ("First number: %d\n",rand() % 100);
srand ( time(NULL) );
printf ("Random number: %d\n",rand() % 100);
srand ( 1 );
printf ("Again the first number: %d\n",rand() %100);
return 0;
}
有以下输出:
First number: 41
Random number: 13
Again the first number: 41
还有以下规则:
Two different initializations with the same seed,instructs the pseudo-random generator to generate the same succession of results for the subsequent calls to rand in both cases.
我理解这些词,但我只是不理解方法本身.为什么它再次回归41?它是随机的还是必须根据此代码在每种情况下返回相同的结果?