C++拾遗

记录一些C++常见问题

获得0-100的随机数

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
#include <vector>
#include <cstdlib>
#include <ctime>
using namespace std;

int main(){
srand((int)time(0)); // 产生随机种子 把0换成NULL也行
int targetNumber = rand() % 100;
cout << "target number is " << targetNumber << endl;
system("pause");
return 0;
}