use*_*827 2 c++ windows random mingw codeblocks
我写了一个程序,用一个用户指定的边数滚动模具.问题是,它太可预测了.
我正在使用CodeBlocks IDE,编译器是GCC.该程序可以很好地编译为调试和发布版本,但无论我选择什么构建选项,可执行文件每次运行时都会返回相同的值.我不能拥有它,因为它的预期用途是作为桌面RPG工具,如果聪明的玩家知道掷骰子的模式,它会相对容易作弊.
解决此问题的最简单方法是什么?
这是来源:
#include <iostream> /* for input and output */
#include <cstdlib> /* for random numbers */
using namespace std;
void rolldie() {
cout << "How many sides to the die?" << endl << "D";
int die;
cin >> die;
int roll = rand() % die +1;
cout << endl << "The die rolled " << roll << endl << endl << "Roll another? (Y for yes, anything else for no; Capitalization counts) ";
}
int main() {
rolldie();
char again;
cin >> again;
while (again == 89) {
rolldie();
cin >> again;
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3354 次 |
| 最近记录: |