一、基本框架
生成随机数需要用到是#include<stdlib.h>、#include<time.h>
这两个头文件
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main()
{
srand((unsigned)time(NULL));
int a = rand();
return 0;
}
二、随机数生成区间
- 生成[1,10]的随机数
int a = rand()%10 + 1;
- 生成[m,n+m]的随机数
int a = rand()%n + m;