Start loop at a random A_index

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
jnsm
Posts: 11
Joined: 27 Nov 2015, 06:49

Start loop at a random A_index

27 Jan 2016, 04:51

Dear all,

I am enjoying learning AHK, but I need help with this. I have a file of tens of thousands of coordinates (like 182:786) and I want to start it reading at random location every time I run it, to test mouse clicking. I have managed to write a script that reads the coordinates and clicks on screen accordingly, but I can't figure out how to tell it to start at a random location in the file and not at the beginning.

Here is what I've got so far:

Code: Select all

Loop, Read, test.csv
{
  	LineNumber = %A_Index%
	Loop, parse, A_LoopReadLine, CSV
    {
	StringSplit, colon, A_LoopField, :, %A_Tab%%A_Space%
	MyArray_%A_Index%_1 := colon1
	MyArray_%A_Index%_2 := colon2
	msgbox % "X is " MyArray_%A_Index%_1 " and Y is " MyArray_%A_Index%_2
	MouseClick, left,  MyArray_%A_Index%_1,  MyArray_%A_Index%_2
	Random, rand, 1000, 5000
	Sleep, rand	
	}
}
AllUrBaseRBelong2Us
Posts: 35
Joined: 09 Nov 2015, 11:15

Re: Start loop at a random A_index

27 Jan 2016, 06:17

Code: Select all

Random, rand, 1, 10000  ;Ten thousand lines?
Loop, Read, test.csv
{
 	if(A_index==rand)
 	{ 
	Loop, parse, A_LoopReadLine, CSV
   		{
		StringSplit, colon, A_LoopField, :, %A_Tab%%A_Space%
		MyArray_%A_Index%_1 := colon1
		MyArray_%A_Index%_2 := colon2
		msgbox % "X is " MyArray_%A_Index%_1 " and Y is " MyArray_%A_Index%_2
		MouseClick, left,  MyArray_%A_Index%_1,  MyArray_%A_Index%_2
	
		Sleep, 1000	
		}
	}
}
Untested...
jnsm
Posts: 11
Joined: 27 Nov 2015, 06:49

Re: Start loop at a random A_index

27 Jan 2016, 06:45

Thank you AllUrBaseRBelong2Us (love your nick!).

I have tested the code and it does select a random A_index, but the script finishes there, it doesn't go to Random-A_index+1 to continue the loop.

I have replaced == in "if(A_index==rand)" with ">" like "if(A_index>rand)" and now it does what I want.

Have a good day and thank you again.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: apeironn, peter_ahk and 322 guests