如何使用rand随机模拟点击 我在C++中做了自动点击器 它是有效的,但是,我尝试在rand函数中使用一个最小和最大整数来随机化它

如何使用rand随机模拟点击 我在C++中做了自动点击器 它是有效的,但是,我尝试在rand函数中使用一个最小和最大整数来随机化它,c++,random,C++,Random,它随机化,但它从来没有真正超过12厘泊。 我是C++新手,我来自C。< /P> 以下是我的全部代码: #include <iostream> #include<Windows.h> #include<stdlib.h> #include <random> using namespace std; int x = 0, y = 0, Mincps, Maxcps, randomized_cps; bool click = false; int r

它随机化,但它从来没有真正超过12厘泊。 我是C++新手,我来自C。< /P> 以下是我的全部代码:

#include <iostream>
#include<Windows.h>
#include<stdlib.h>
#include <random>
using namespace std;


int x = 0, y = 0, Mincps, Maxcps, randomized_cps;
bool click = false;
int randomize_cps(int min, int max);

void Menu()
{
    system("color 5");
    cout << "Minimum CPS: ";
    cin >> Mincps;

    system("CLS");

    cout << "Maximum CPS: ";
    cin >> Maxcps;
    system("CLS");

    if (Mincps > 20 || Maxcps > 20 || Mincps < 1 || Maxcps < 1)
    {
        cout << "That CPS is not safe" << endl;
        Sleep(1000);
        system("CLS");
        Menu();
    }

    cout << "AirClicker\n";
    cout << "Made by Deagan";
    Sleep(1500);

    system("CLS");

    cout << "Minimum CPS: ";
    cout << Mincps;

    cout << "\n\n";

    cout << "Maximum CPS: ";
    cout << Maxcps;

    cout << "\n\n";

    cout << "Press X to toggle on and Z to toggle off.\n";
}

void Clicker()
{

    while (1)
    {
        if (GetAsyncKeyState('X'))
        {
            click = true;
        }

        if (GetAsyncKeyState('Z'))
        {
            click = false;
        }

        if (click == true)
        {
            mouse_event(MOUSEEVENTF_LEFTDOWN, x, y, 0, 0);
            mouse_event(MOUSEEVENTF_LEFTUP, x, y, 0, 0);
            Sleep(1000 / randomized_cps);
        }
    }
}

int main()
{
    Menu();
    Clicker();
}

int randomize_cps(int min, int max)
{
    std::random_device rd;
    std::mt19937 gen(rd());
    std::uniform_int_distribution<> distr(Mincps, Maxcps);
    randomized_cps = distr(gen);
    return 0;
}
#包括
#包括
#包括
#包括
使用名称空间std;
int x=0,y=0,Mincps,Maxcps,随机化_-cps;
bool click=false;
int随机化_cps(int最小值,int最大值);
无效菜单()
{
系统(“彩色5”);
cout>Mincps;
系统(“CLS”);
cout>Maxcps;
系统(“CLS”);
如果(Mincps>20 | | Maxcps>20 | | Mincps<1 | | Maxcps<1)
{

cout这将根据需要为1到20之间的随机值休眠:

#include <Windows.h>
#include <iostream>
#include <random>

int main()
{
    std::default_random_engine generator;
    std::uniform_int_distribution<int> distribution(1, 20);

    while (1)
    {
        int random_value = distribution(generator);
        std::cout << random_value << std::endl;
        Sleep(random_value); // this is already in milliseconds
    }

    return 0;
}
#包括
#包括
#包括
int main()
{
std::默认随机引擎生成器;
标准:均匀分布(1,20);
而(1)
{
int random_值=分布(生成器);

std::cout这将根据需要为1到20之间的随机值休眠:

#include <Windows.h>
#include <iostream>
#include <random>

int main()
{
    std::default_random_engine generator;
    std::uniform_int_distribution<int> distribution(1, 20);

    while (1)
    {
        int random_value = distribution(generator);
        std::cout << random_value << std::endl;
        Sleep(random_value); // this is already in milliseconds
    }

    return 0;
}
#包括
#包括
#包括
int main()
{
std::默认随机引擎生成器;
标准:均匀分布(1,20);
而(1)
{
int random_值=分布(生成器);

std::cout我建议您做两件事:1-读取,否则您的rand将始终返回相同的值。2-提供您用于应用程序的输入(例如:max,min value)没有调用
srand()
。但我觉得有趣的是,你有
#包含
,然后不使用它提供的高级随机数功能。如果你想随机计算两次单击之间的持续时间,你需要在每次单击时进行随机计算,而不是在程序启动时进行一次。@cdhowie谢谢你!我知道了,但有一个问题。CPS通常保持在最小CPS附近,不会上升到最大值。我现在使用的是rand,而不是rand。@DeaganMuir使用新代码更新此问题中的代码。我建议您做两件事:1-读取,否则rand将始终返回相同的值。2-提供应用程序使用的输入(例如:max,min value)没有对
srand()的调用
。但我觉得有趣的是,你有
#包含
,然后不使用它提供的高级随机数功能。如果你想随机计算两次单击之间的持续时间,你需要在每次单击时进行随机计算,而不是在程序启动时进行一次。@cdhowie谢谢你!我知道了,但有一个问题。CPS通常保持在最小CPS附近,不会上升到最大值。我现在使用的是rand而不是rand。@DeaganMuir用您的新代码更新此问题中的代码。