【问题标题】:How to randomize simulated clicks using rand如何使用 rand 随机化模拟点击
【发布时间】:2020-06-18 15:17:56
【问题描述】:

我正在用 C++ 制作一个自动点击器 它可以工作,但是,我正在尝试使用 rand 函数中的最小和最大整数对其进行随机化。

它是随机的,但它从未真正超过 12 cps。 我是 C++ 新手,我来自 C#。

这是我所有的代码:

#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;
}

感谢任何帮助,谢谢! 有人请帮我弄随机器,应该在几天内完成。

【问题讨论】:

  • 我建议你做两件事:1-阅读 stackoverflow.com/questions/322938/… ,否则你的 rand 将始终返回相同的值。 2 - 提供您用于应用程序的输入(例如:最大值、最小值)
  • 没有呼叫srand()。但我觉得有趣的是,你有 #include &lt;random&gt;,然后不使用它提供的高级随机数工具。
  • 如果您希望点击之间的持续时间是随机的,您需要在程序启动时进行一次随机计算每次点击
  • @cdhowie 谢谢!我想通了,但有一个问题。 CPS 通常保持在 min cps 左右,不会上升到最大值。我现在使用 而不是 rand。
  • @DeaganMuir 使用您的新代码更新此问题中的代码。

标签: c++ random


【解决方案1】:

这将根据需要休眠 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;
}

【讨论】:

    猜你喜欢
    • 2020-01-20
    • 1970-01-01
    • 1970-01-01
    • 2011-02-11
    • 1970-01-01
    • 1970-01-01
    • 2020-04-21
    • 1970-01-01
    相关资源
    最近更新 更多