gpt4 book ai didi

C++ 随机数生成器只输出 2

转载 作者:行者123 更新时间:2023-11-28 06:38:54 26 4
gpt4 key购买 nike

<分区>

代码运行,但随机数生成器只输出数字 2。我输入了漏洞代码以防万一有任何我没有想到的因素。有没有更方便的方法来使用随机数生成器?

#include <windows.h>
#include <stdio.h>
#include <tchar.h>
#include <iostream>
#include <string>
#include <chrono>
#include <thread>

int Time();
int RanNum1to10();

void main()
{
time_t now = time(0);
tm *ltm = localtime(&now);
int hour = ltm->tm_hour;
int min = 1 + ltm->tm_min;
int sec = 1 + ltm->tm_sec;
int RanNum = RanNum1to10();
std::string text;
std::getline(std::cin, text);
{
if(text.find("hi") != std::string::npos)
{
RanNum1to10();
if (RanNum >= 1 && RanNum <= 4)
{
Time();
if(hour >= 0 && hour <= 11)
{
std::cout << "good morning" << std::endl;
}
if(hour >= 12 && hour <= 17)
{
std::cout << "good afternoon" << std::endl;
}
if(hour >= 18 && hour <= 23)
{
std::cout << "good evening" << std::endl;
}
}
if (RanNum >= 5 && RanNum <= 6)
{
{
std::cout << "hey" << std::endl;
}
}
if (RanNum >= 7 && RanNum <= 8)
{
{
std::cout << "hello" << std::endl;
}
}
if (RanNum >= 9 && RanNum <= 10)
{
{
std::cout << "hi" << std::endl;
}
}
std::cout << RanNum;
std::cout << std::endl;
}
}
system("pause");
}
int RanNum1to10()
{
return (rand() % 10 + 1);
}
int Time()
{
time_t now = time(0);
tm *ltm = localtime(&now);
int hour = ltm->tm_hour;
int min = 1 + ltm->tm_min;
int sec = 1 + ltm->tm_sec;
return hour && min && sec;
}

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com