Beginner "Pseudo-random" Question Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Pharma
Posts: 26
Joined: 13 Dec 2016, 18:14

Beginner "Pseudo-random" Question

21 Sep 2017, 14:49

Hey all,

Sorry if this has been done many times. Wasn't sure what to search.

Anyways, I'm trying to make my "randomly" generated points a little more human-like.
The two lines between the ###'s below are the parts I'd like to fix.

Code: Select all

	StartX := 0
	StartY := 0

; ############	
	
	Random, X_Offset, -10, 10
	Random, Y_Offset, -10, 10

; ############

	StartX += X_Offset
	StartY += Y_Offset						

	Call_Bezier(0, 0, StartX, StartY, 232, 378, "RO P2-3")				
	call_Sleep(100,120)
	MouseClick, Left
	call_Sleep(200,2300)	
Problem is that I don't know how to even begin to script such a thing.
This Box Muller Transform looks pretty damn good.
But maybe this is too much to ask.

I think anything that would kind of make it humanlike would suffice.

Image

Thanks!
User avatar
KuroiLight
Posts: 327
Joined: 12 Apr 2015, 20:24
Contact:

Re: Beginner "Pseudo-random" Question

21 Sep 2017, 15:01

I'm far from a mathmatician and I'm not exactly sure what the difference between human-like and computer would be, but you could try smoothing the plot points.
e.g make each new plot the average between previous and current point
pseudo code example:

Code: Select all

current_point := generate_new_point()
actual_point := average(current_point, last_point)
plot(actual_point)
static last_point := actual_point
:think: not sure if thats what your looking for but in theory it might look more like the box-muller picture than the uniform picture.
Windows 10, Ryzen 1600, 16GB G.Skill DDR4, 8GB RX 480 | [MyScripts][MySublimeSettings] [Unlicense][MIT License]
01/24/18
[/color]
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Beginner "Pseudo-random" Question  Topic is solved

21 Sep 2017, 17:50

It is a very simple transformation. Try it in fullscreen paint and press space to start it.

Code: Select all

radius:=50
O:={x:(A_ScreenWidth-radius)//2,  y:(A_ScreenHeight-radius)//2}
CoordMode,Mouse,Screen
SetDefaultMouseSpeed,0
SetMouseDelay,-1
keywait,space,d
loop 600 {
	coord:=r()
	click % O.x+coord.x*Radius ", " O.y+coord.y*Radius
}
esc::exitapp
r(){
	static pi:=3.1
	local u1,u2,R
	random, u1,0.0,1.0
	random, u2,0.0,1.0
	R:=sqrt(-2*ln(u1))
	return {x:R*cos(2*pi*u2),y:R*sin(2*pi*u2)}
}
Edit:
normal.png
normal.png (8.17 KiB) Viewed 4947 times
User avatar
KuroiLight
Posts: 327
Joined: 12 Apr 2015, 20:24
Contact:

Re: Beginner "Pseudo-random" Question

21 Sep 2017, 21:30

interesting, whats it for? if i may ask
Windows 10, Ryzen 1600, 16GB G.Skill DDR4, 8GB RX 480 | [MyScripts][MySublimeSettings] [Unlicense][MIT License]
01/24/18
[/color]
User avatar
Brazolek123
Posts: 187
Joined: 06 Jun 2016, 16:02

Re: Beginner "Pseudo-random" Question

22 Sep 2017, 02:26

https://autohotkey.com/board/topic/6461 ... om-number/

Normal distribution in both axis might result in such effect.
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Beginner "Pseudo-random" Question

22 Sep 2017, 02:37

Brazolek123, the Box-Muller transfromation, yields a normal distrubution.
User avatar
Gio
Posts: 1247
Joined: 30 Sep 2013, 10:54
Location: Brazil

Re: Beginner "Pseudo-random" Question

22 Sep 2017, 15:44

Anyways, I'm trying to make my "randomly" generated points a little more human-like.
If this is to fool an anti-bot software like those of MMO games, you better know that it is actually not hard to figure out someone is using a "weighted" form of randomness such as box muller transformation in their clicks. Any randomness algorithm you can come up will probably differ greatly from an actual human sample in no time. Your best shot to look "human like" is to collect actual human behaviour, shuffle it and than replicate. One such example is to collect the coordinates and timing of thousands of actual human clicks (record them for 1-2 hours), shuffle the sequences of coordinates and times and run the new set. This will include a distinct human behaviour pattern that is very hard for any anti-bot to find out.
Pharma
Posts: 26
Joined: 13 Dec 2016, 18:14

Re: Beginner "Pseudo-random" Question

24 Sep 2017, 13:34

Hello all,

Sorry for the delayed response.
Took me awhile to test and understand the code.

What I ended up doing was mix the AHK random and Helgef's Box-Miller Transform.
Below is part of my script.
Seems to be working!

Thank you all for your help!

Code: Select all

	Random, RNG, 1, 10
	if ( RNG <= 5 ) 
		{
; AHK Built-In Random
			Random, X_Offset, 0, 10
			Random, Y_Offset, 0, 10
			X_Current += X_Offset
			Y_Current += Y_Offset									
			
			Call_Bezier(0, 0, X_Current, Y_Current, 60, 120, "RO P1-2")
			MouseClick, Left
			call_Sleep(50,100) 
		}
	else
		{
; Box-Miller Transform	
			Radius:=3
			O:={X:(X_Current-Radius),  Y:(Y_Current-Radius)}
			
			static pi:=3.1
			random, Coeff_1,0.0,1.0
			random, Coeff_2,0.0,1.0							
			BMT_math:=sqrt(-2*ln(Coeff_1))
			
			Coord:={X:(BMT_math*cos(2*pi*Coeff_2)), Y:(BMT_math*sin(2*pi*Coeff_2))}
			
			X_Current := O.X + Coord.X * Radius
			Y_Current := O.Y + Coord.Y * Radius					
			
			Call_Bezier(0, 0, X_Current, Y_Current, 50, 130, "RO P1-2")
			MouseClick, Left
			call_Sleep(50,100)	
		}		

User avatar
KuroiLight
Posts: 327
Joined: 12 Apr 2015, 20:24
Contact:

Re: Beginner "Pseudo-random" Question

25 Sep 2017, 21:11

I know this questions been solved and all, but I decided I'd take a stab at this sort of algorithm myself, despite my extreme lack of math skills...
so I started out generating this (averaging with basevalue)
#1Image
then I got it to here (+noise)
#2Image
now (without noise) (averaging with prior value)
#3Image and with noise (averaging with prior value) #4Image
more like The UnMathematician's False-Box Muller, lol
Like I said bare in mind I have very poor math skills.
*EDIT*
After an idea hit me to try utilizing 3 uniform-boxes with progressively less chance of hitting outer boxes
TripleBoxRandom
#5Image
then I added smoothing (averaging with prior value)
#6Image and a version with tweaked uniform box generation #7Image
*EDIT* 2
Heres an example from the code used in picture #4 with a bug-fix (which was causing a negative value bias)
#8Image

I imagine if one did averaging with more than 2 values, periodically inserting the center value in there you could get a nice looking center biased plot.
here is one where I average 3 values [prior, new and center]
#9Image or 50% chance to average with center #10Image
Windows 10, Ryzen 1600, 16GB G.Skill DDR4, 8GB RX 480 | [MyScripts][MySublimeSettings] [Unlicense][MIT License]
01/24/18
[/color]
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Beginner "Pseudo-random" Question

26 Sep 2017, 05:36

KuroiLight, nice job :thumbup: But where is the code :?: :geek:
User avatar
KuroiLight
Posts: 327
Joined: 12 Apr 2015, 20:24
Contact:

Re: Beginner "Pseudo-random" Question

26 Sep 2017, 09:39

I cleaned it up a bit but It's not pretty and could probably be optimized.
#3 & #8:
ImageImage

Code: Select all

;Author KuroiLight/[email protected]
;License MIT
#NoEnv
CoordMode, Mouse, Screen
;#Warn
SendMode Input
SetWorkingDir %A_ScriptDir%

Random,,%A_TickCount%
timer_on := false
return

GetWeightedRandom(varName, base, diff) {
    static prior_base := {}
    if(prior_base[varName] == "")
        prior_base[varName] := base
    Random, random_base, % (prior_base[varName] - diff), % (prior_base[varName] + diff)
    next_random := (base + random_base) / 2
    prior_base[varName] := next_random
    return Round(next_random)
}

GetNoise(varName, rnd, every, tick_variance, spike_variance) {
    static tickCounts := {}
    if(tickCounts[varName] == "")
        tickCounts[varName] := 0
    tickCounts[varName] += 1
    Random, every, % (every - tick_variance), % (every + tick_variance)
    if(tickCounts[varName] > every) {
        tickCounts[varName] := 0
        return GetWeightedRandom(varName, rnd, spike_variance)
    }
    return rnd
}

F1::
    if(timer_on) {
        MouseMove, mx, my
    } else {
        MouseGetPos, mx, my
    }
    timer_on := !timer_on
    SetTimer, main, 10
    SetTimer, main, % (timer_on ? "On" : "Off")
return

main:
    ;without noise
    ; newX := GetWeightedRandom("X", mx, 25)
    ; newY := GetWeightedRandom("Y", my, 25)

    ;with noise
    newX := GetNoise("X", GetWeightedRandom("X", mx, 100), 3, 2, 100)
    newY := GetNoise("Y", GetWeightedRandom("Y", my, 100), 3, 2, 100)

    ToolTip, % "Variance X=" . (mx - newX) . " Y=" . (my - newY), 0, 0, 1
    MouseClick, Left, %newX%, %newY%, 1
return
#5 & #7 & #10
ImageImageImage

Code: Select all

;Author KuroiLight/[email protected]
;License MIT
#NoEnv
CoordMode, Mouse, Screen
;#Warn
SendMode Input
SetWorkingDir %A_ScriptDir%

Random,,%A_TickCount%
timer_on := false
return


AddSmoothing(varName, newVal) {
    static prior_base := {}
    if(prior_base[varName] == "")
        prior_base[varName] := newVal
    prior_base[varName] := (prior_base[varName] + newVal) / 2
    return prior_base[varName]
}

AddSmoothingCenter(varName, newVal, base) {
    static prior_base := {}
    if(prior_base[varName] == "")
        prior_base[varName] := newVal
    Random, bias_chance, 1, 2
    if(bias_chance > 1) {
        prior_base[varName] := (prior_base[varName] + newVal) / 2
    } else {
        prior_base[varName] := (prior_base[varName] + newVal + base) / 3
    }
    return prior_base[varName]
}

TripleBoxRandom(base, max_variance) {
    inner := (max_variance / 3)
    outer := inner * 2
    orbit := inner * 3

    low_inner := (base - inner), high_inner := (base + inner)
    low_outer := (base - outer), high_outer := (base + outer)
    low_orbit := (base - orbit), high_orbit := (base + orbit)

    Random, rng_base, %low_inner%, %high_inner%
    ;if(rng_base > (base + (inner / 2)) or rng_base < (base - (inner / 2))) {
        Random, roll, 1, 2
        if(roll > 1) {
            Random, rng_base, %low_outer%, %high_outer%
            ;if(rng_base > (base + (outer / 2)) or rng_base < (base - (outer / 2))) {
                Random, roll, 1, 2
                if(roll > 1) {
                    Random, rng_base, %low_orbit%, %high_orbit%
                }
            ;}
        }
    ;}
    return rng_base
}

F1::
    if(timer_on) {
        MouseMove, mx, my
    } else {
        MouseGetPos, mx, my
        ;init smoothers
        AddSmoothing("newX", mx)
        AddSmoothing("newY", my)
        AddSmoothingCenter("newX", mx, mx)
        AddSmoothingCenter("newY", my, my)
    }
    timer_on := !timer_on
    SetTimer, main, 10
    SetTimer, main, % (timer_on ? "On" : "Off")
return

main:
    ;TripleBoxGenerator
    ; newX := TripleBoxRandom(mx, 75)
    ; newY := TripleBoxRandom(my, 75)

    ;with prior value smoothing
    newX := AddSmoothing("newX", TripleBoxRandom(mx, 200))
    newY := AddSmoothing("newY", TripleBoxRandom(my, 200))

    ;with center value smoothing
    ; newX := AddSmoothingCenter("newX", TripleBoxRandom(mx, 200), mx)
    ; newY := AddSmoothingCenter("newY", TripleBoxRandom(my, 200), my)

    ToolTip, % "Variance X=" . (mx - newX) . " Y=" . (my - newY), 0, 0, 1
    MouseClick, Left, %newX%, %newY%, 1
return
Windows 10, Ryzen 1600, 16GB G.Skill DDR4, 8GB RX 480 | [MyScripts][MySublimeSettings] [Unlicense][MIT License]
01/24/18
[/color]
User avatar
FanaticGuru
Posts: 1906
Joined: 30 Sep 2013, 22:25

Re: Beginner "Pseudo-random" Question

26 Sep 2017, 14:56

Gio wrote:
Anyways, I'm trying to make my "randomly" generated points a little more human-like.
If this is to fool an anti-bot software like those of MMO games, you better know that it is actually not hard to figure out someone is using a "weighted" form of randomness such as box muller transformation in their clicks. Any randomness algorithm you can come up will probably differ greatly from an actual human sample in no time. Your best shot to look "human like" is to collect actual human behaviour, shuffle it and than replicate. One such example is to collect the coordinates and timing of thousands of actual human clicks (record them for 1-2 hours), shuffle the sequences of coordinates and times and run the new set. This will include a distinct human behaviour pattern that is very hard for any anti-bot to find out.
I agree with Gio. None of the examples in this thread look to me like what a human click pattern would look like. The problem is that they all look too random.

From what I have seen, human click patterns tend to have a skewed axis aligned toward the center of the screen based on the position of the button being clicked. ie. A button in the far bottom right has a different click pattern than a button slightly off center to the left. Kind of a vaguely tear drop type shape. The shape of the button also plays a role. The script has to miss clicking on the button sometimes. The list goes on and on. The game has the advantage that is can collect the data from millions of human clicks and can look for any pattern that is out of the norm.

If the game was to actually track mouse movement, speed, and timing then it really becomes hard to look human with math. Bézier Curves and the likes are better than a straight line but they are far from human. On the plus side the game will probably be analysis the pattern with math so you just need a random algorithm good enough to fool their detection algorithm.

The sampling of actual human movements would probably be pretty good but intensive to develop and implement.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
User avatar
KuroiLight
Posts: 327
Joined: 12 Apr 2015, 20:24
Contact:

Re: Beginner "Pseudo-random" Question

26 Sep 2017, 15:24

FanaticGuru wrote: From what I have seen, human click patterns tend to have a skewed axis aligned toward the center of the screen based on the position of the button being clicked. ie. A button in the far bottom right has a different click pattern than a button slightly off center to the left. Kind of a vaguely tear drop type shape.

FG
Maybe like this?
Image
The first one is with center smoothing offset right and slightly down, second one is just offset right.
*EDIT*
Seems a bit harder to get that teardrop shape without using actual maths, will experiment a bit and try for a sort of fireball shape if I can.
Windows 10, Ryzen 1600, 16GB G.Skill DDR4, 8GB RX 480 | [MyScripts][MySublimeSettings] [Unlicense][MIT License]
01/24/18
[/color]
User avatar
FanaticGuru
Posts: 1906
Joined: 30 Sep 2013, 22:25

Re: Beginner "Pseudo-random" Question

26 Sep 2017, 17:19

KuroiLight wrote:Maybe like this?
Image
The first one is with center smoothing offset right and slightly down, second one is just offset right.
These are better. For a rectangular button to the middle left of center of screen.

If the button was near the bottom left of the screen it would kind of have a counter clockwise twist to the axis. But it is not really a simple twist it is a skew in two directions.

Even for a button straight left of center, your pattern distribution is too symmetrically top and bottom. From what I read awhile back when I played with similar coding, humans tend to click a little more randomly high so that the top is more random and inaccurate than the bottom.

Your top one is more of this idea of skewing in two directions but at a glance it seems too blocky but on a rectangular button that might actual be it but I like the distribution from the center better on the second but too symmetrical top and bottom. You don't want the pattern to be too symmetrical on any axis as that is math that a detection algorithm could look for. From what I understand with real human movement it is a skew on multiple axis based on multiple factors. Arm movement will cause it to be skewed one way in the direction that arms move naturally, hand movement to be skewed another as wrist tend to move better side to side than up and down, fingers, eyes, psychology, etc. tending to make errors in multiple discernable axis.

Below is a related thread.
https://autohotkey.com/board/topic/9925 ... d-formula/
It has some equations and math that I played with in the past. It was during this time that I researched human mouse moving and click to discover that it is pretty hard to do really good because humans don't really move and click at random.

Now don't get me wrong, you can definitely do it well enough to fool most games as they don't want to spend the processing power and bandwidth not to mention the coding expertise to implement really good. It is just hard to fool a focused analysis. Game companies don't really care about cheating, only disruption. If the cheating is not affecting their servers or other players too much, they don't care too much. There are other statistics that are easier to collect to flag suspicious play.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
User avatar
KuroiLight
Posts: 327
Joined: 12 Apr 2015, 20:24
Contact:

Re: Beginner "Pseudo-random" Question

26 Sep 2017, 19:32

FanaticGuru wrote: Now don't get me wrong, you can definitely do it well enough to fool most games as they don't want to spend the processing power and bandwidth not to mention the coding expertise to implement really good. It is just hard to fool a focused analysis. Game companies don't really care about cheating, only disruption. If the cheating is not affecting their servers or other players too much, they don't care too much. There are other statistics that are easier to collect to flag suspicious play.

FG
I would think most anti-cheats, if they even implement any sort of click analysis would focus more on click times than locations, unless ofcoarse your bot or what ever was clicking the same spots every time then it would be pretty obvious.
Anyways I was just doing to see if I could with few math skills, Ill more than likely use the random generation for 1-dimensional sleeps/timers/clicktimes to make things like auto-clickers look more organic than a simple random.
heres a visualization of what I mean, (mind the poor gif speed)
Image
Windows 10, Ryzen 1600, 16GB G.Skill DDR4, 8GB RX 480 | [MyScripts][MySublimeSettings] [Unlicense][MIT License]
01/24/18
[/color]

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: garry, Google [Bot], marypoppins_1, Rohwedder, RussF and 142 guests