user-0 提问: 问一个关于rand函数的问题！

回复:
user: user-0
content: 引用 3 楼 user-1 的回复:你这不是注释得很详细得么，while每次循环都调用了设置了两次种子  是我开始理解错了。。。谢谢你

user: user-1
content: 你这不是注释得很详细得么，while每次循环都调用了设置了两次种子

user: user-0
content: 引用 1 楼 user-1 的回复:你这儿只设置了一次种子啊，所以只有一串序列。  你是想说，你在同一秒内启动了该程序的两个进程，这两天进程生成的序列不一样么？  还是想不通在下面这个程序中可以第二次调用rand()来检查输入 说明两次rand返回的序列是一样的 可为什么在第一个程序中不行呢 /* Program 4.12 Simple Simon */ #include <stdio.h>                     /* For input and output   */ #include <ctype.h>                     /* For toupper() function */ #include <stdbool.h>                   /* For bool, true, false  */ #include <stdlib.h>                    /* For rand() and srand() */ #include <time.h>                      /* For time() and clock() */  int main(void) {   /* Records if another game is to be played */   char another_game = 'Y';    /* true if correct sequence entered, false otherwise */   int correct = false;    /* Number of sequences entered successfully          */   int counter = 0;    int sequence_length = 0;     /* Number of digits in a sequence        */   time_t seed = 0;             /* Seed value for random number sequence */   int number = 0;              /* Stores an input digit                 */    time_t now = 0;            /* Stores current time - seed for random values  */   int time_taken = 0;        /* Time taken for game in seconds                */    printf("\nTo play Simple Simon, ");   printf("watch the screen for a sequence of digits.");   printf("\nWatch carefully, as the digits are only displayed"                                                 " for a second! ");   printf("\nThe computer will remove them, and then prompt you ");   printf("to enter the same sequence.");   printf("\nWhen you do, you must put spaces between the digits. \n");   printf("\nGood Luck!\nPress Enter to play\n");   scanf("%c", &another_game);    do   {     correct = true;         /* By default indicates correct sequence entered */     counter = 0;            /* Initialize count of number of successful tries*/     sequence_length = 2;    /* Initial length of a digit sequence            */      while(correct)     {       /* On every third successful try, increase the sequence length */       sequence_length += counter++%3 == 0;        seed = time(NULL);        now = clock();                  /* record start time for sequence  */        srand((unsigned int)seed);      /* Initialize the random sequence */       for(int i = 1; i <= sequence_length; i++)         printf("%d ", rand() % 10);    /* Output a random digit          */       fflush(stdout);       /* Wait one second */       for( ;clock() - now < CLOCKS_PER_SEC; );        printf("\r");                   /* go to beginning of the line */       for(int i = 1; i <= sequence_length; i++)         printf("  ");                 /* Output two spaces */        srand((unsigned int)seed);     /* Restart the random sequence    */       for(int i = 1; i <= sequence_length; i++)       {         scanf("%d", &number);         /* Read an input number         */         if(number != rand() % 10)     /* Compare against random digit */         {           correct = false;            /* Incorrect entry             */           break;                      /* No need to check further... */         }       }       printf("%s\n", correct? "Correct!" : "Wrong!");     }      int c;     while((c = getchar()) != '\n' && c != EOF);      printf("\nDo you want to play again (y/n)? ");     scanf("%c", &another_game);    }while(toupper(another_game) == 'Y');   return 0; }

user: user-1
content: 你这儿只设置了一次种子啊，所以只有一串序列。  你是想说，你在同一秒内启动了该程序的两个进程，这两天进程生成的序列不一样么？