C++伪随机数
直接上代码吧
用的是vs2019
#include <iostream>
using namespace std;
int main() {
// 系统生成随机数 // rand()%100 生成 0~99
srand(time(NULL)); // 随机数种子,不加这行下一行就是伪随机数
int random_num = rand() % 100 + 1; // 1-100;
//cout << random_num << endl;
while (true)
{
int guess;
cout << "输出你猜的数:";
cin >> guess;
if (random_num == guess)
{
cout << "恭喜你!猜对了" << endl;
break;
}
else if (random_num > guess)
{
cout << "猜小了!" << endl;
}
else
{
cout << "猜大了!" << endl;
}
}
return 0;
}
本文来自博客园,作者:__username,转载请注明原文链接:https://www.cnblogs.com/code3/p/17300027.html