Search code examples
randomautohotkey

AutoHotkey Code for Randomly generating number not working anymore


The following code presses the cursor every few seconds. When I first made it, it just pressed the cursor every 5 seconds, but the game realised what I was doing. So I changed the code, with the help of ChatGPT and made the following. The code has been working for about 6 months, but no longer works. Chat says the code is fine, and we went through it all, doing various tests. But I still can't find out why the 'Random' procedure won't work.

Does anyone have any ideas.

I use it to press the curser on an silly online game when I'm out.

SetBatchLines -1  ; Improve script performance

Loop
{
    Random, ClickInterval, 400000, 1000000  ; Generate a random number between 400000 and 1000000 milliseconds (4.0 to 10.0 seconds)
    Click           ; Click at the current cursor position
    Sleep, ClickInterval
}

Solution

  • It seems that there's a misunderstanding about the time duration in milliseconds.

    400000 milliseconds is equal to 400 seconds, not 4 seconds.

    If you intended to generate a random time between 4 and 10 seconds in milliseconds, you should use a range of 4000 to 10000 milliseconds (4 seconds to 10 seconds).

    Here's the corrected code snippet:

    SetBatchLines -1  ; Improve script performance
    
    Loop
    {
        Random, ClickInterval, 4000, 10000  ; Generate a random number between 4000 and 10000 milliseconds (4 to 10 seconds)
        Click           ; Click at the current cursor position
        Sleep, ClickInterval
    }
    

    Just to you understand what is happening in your code, try this:

    SetBatchLines -1  ; Improve script performance
    
    Loop
    {
        Random, ClickInterval, 400000, 1000000
        Click
        ToolTip, % "Waiting " Round( ClickInterval/1000 ) " seconds to click again."
        count(ClickInterval)
    
    }
    
    count(interval) {
    
        Loop,% Round( interval/1000 )   {
            Sleep, 1000
            ToolTip, % "Waiting " round( interval/1000 ) - A_Index " seconds to click again."
        }
        return
    }