#include <stdio.h>
#include <time.h>
#include <stdlib.h>
int main()
{
time_t tm = time(NULL);//得到系统时间
srand((unsigned int)tm);//随机种子只需要设置一次即可
int r = rand()%10 + 1;
printf("r = %d\n", r);
return 0;
}
生成1-10的随机数
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
int main()
{
time_t tm = time(NULL);//得到系统时间
srand((unsigned int)tm);//随机种子只需要设置一次即可
int r = rand()%10 + 1;
printf("r = %d\n", r);
return 0;
}
生成1-10的随机数