【发布时间】:2013-02-10 06:08:16
【问题描述】:
考虑这段代码:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main ()
{
int ctr;
for(ctr=0;ctr<=10;ctr++)
{
int iSecret;
srand ( time(NULL) );
printf("%d\n",iSecret = rand() % 1000 + 1);
}
}
它会输出: 256 256 256 256 256 256 256 256 256 256
不幸的是,我希望输出在该循环中打印 10 个不同的随机数。
【问题讨论】:
-
将那些能帮助你的人称为“天才”可能会被认为是粗鲁的。我建议你编辑你的帖子。
-
你为什么一直srand呢?