代码如下:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(void)
{
int r;
int i;
for (i = 0; i < 100; i++)
{
r = rand() % 100 + 1;
printf("%d\n", r);
}
return 0;
}
我一直在尝试随机数,但是有一天,我忘了把 srand()
放进去,但是 rand()
函数仍然可以随机一个数(相同的顺序)。
问题是,如果我不指定它使用什么种子?
最佳答案
如果未调用 srand,则 rand 就像调用了 srand(1) 一样。
http://www.acm.uiuc.edu/webmonkeys/book/c_guide/2.13.html#rand
关于c - 如果我不指定 srand(),rand() 使用什么种子?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14251452/