- 生成0~9的随机数
#include <stdlib.h>
#include <time.h>
using namespace std;
int main() {
srand(unsigned(time(0)));
int number = rand() % 10;
return 0;
}
- 生成1~10的随机数
#include <stdlib.h>
#include <time.h>
using namespace std;
int main() {
srand(unsigned(time(0)));
int number = rand() % 10 + 1;
return 0;
}