c语言生成随机数
记录示例,留作自用
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(void)
{
//设置当前时间戳作为rand的种子
srand((unsigned int)time(NULL));
//生成随机数
int rnd = rand();
printf("生成了随机数: %d\n", rnd);
return 0;
}
记录示例,留作自用
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(void)
{
//设置当前时间戳作为rand的种子
srand((unsigned int)time(NULL));
//生成随机数
int rnd = rand();
printf("生成了随机数: %d\n", rnd);
return 0;
}