c 语言中随机产生一个数字
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
int main()
{
srand( (unsigned)time( NULL ) );
printf("%d\n",rand());
return 0;
}
本文介绍了一种在C语言中生成随机数的方法。通过使用srand()和time()函数进行种子初始化,确保每次运行程序时都能得到不同的随机数。rand()函数随后被用来生成具体的随机数值。
c 语言中随机产生一个数字
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
int main()
{
srand( (unsigned)time( NULL ) );
printf("%d\n",rand());
return 0;
}
473
1万+

被折叠的 条评论
为什么被折叠?