C++生成随机整数和随机种子

C++生成随机整数和随机种子

#include <iostream>
#include <ctime>
using namespace std;
int main() {
	//系统要生成一个随机数
	srand((unsigned)time(NULL));  // 添加随机种子
	int num = rand() % 100 + 1;  // 生成一个1至100的整数
    cout << num << endl;
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_38463737/article/details/125227406