c++ - Srand 正在输出一个巨大的数字列表,而不仅仅是一个
问题描述
我正在使用 C++,而且我很新,但我最近遇到的麻烦之一是使用 srand。Srand 正在输出一个庞大的数字列表,直到它移动到下一个。这是我的代码,所以你可以理解我在说什么
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string>
using namespace std;
void function2()
{
int num;
string none;
string end1;
while (num != 69420)
{
srand((unsigned) time( NULL));
num = rand() % 100000 + 1;
cout << num << "\n";
}
if (num != 69420)
{
cout << "gg's";
cin >> end1;
}
}
int main()
{
int num;
string none;
while (num != 69420)
{
srand((unsigned) time( NULL));
num = rand() % 100000 + 1;
cout << "Press enter.";
getline(cin, none);
if (none == " ")
{
}
else
{
function2();
}
if (num != 69420)
{
break;
}
else
{
continue;
}
}
}
这可能是不对的,这就是我在这里的原因。感谢任何人,如果你试图帮助我!
解决方案
推荐阅读
- python - 如何在python中实现稀疏矩阵
- python - 如何使 python pyinstaller 可执行文件可共享
- python - Sphero - OverflowError:Python int 太大而无法转换为 C long
- java - 如何解决 Intellij Idea 的“无法启动 Scala 编译服务器”?
- node.js - 从迅雷客户端发送承载授权请求时,标题内容[“授权”]中的字符无效
- python - 将 Seaborn Plot 保存为 PDF 会移动颜色条框架
- ckeditor - CKEditor 4 自定义编辑器显示但无法正常工作
- flutter - 无法使用另一个小部件中存在的列表
- django - 输出中的 Django 新行
- amazon-s3 - 如何限制 Visual Studio AWS Explorer 中列出的 S3 存储桶