i need help how to random the loops not to be in order

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
T0oji
Posts: 1
Joined: 01 May 2024, 01:00

i need help how to random the loops not to be in order

01 May 2024, 01:06

so guy i have made this script that has like 20 different loops but i need help to know how to make it random changes between it not to go in the same Specific order every time

loop
{ do stuff} ;loop1


loop
{ do stuff} ;loop2

loop
{ do stuff} ;loop3

loop
{ do stuff} ;loop4

;and on.....

so i want it to shuffle between loops not to go from 1 to 20 in same order everytime
User avatar
boiler
Posts: 17193
Joined: 21 Dec 2014, 02:44

Re: i need help how to random the loops not to be in order

01 May 2024, 01:31

This performs each “loop” exactly once in random order. Just replace the MsgBox lines with the loop and whatever code you want to perform in each one.

Code: Select all

#Requires AutoHotkey v2.0

NumList := ''
loop 20
	NumList .= A_Index '`n'
NumList := Sort(RTrim(NumList, '`n'), 'Random')
loop parse NumList, '`n'
	Func%A_LoopField%()

Func1() {
	MsgBox 'Loop 1'
}

Func2() {
	MsgBox 'Loop 2'
}

Func3() {
	MsgBox 'Loop 3'
}

Func4() {
	MsgBox 'Loop 4'
}

Func5() {
	MsgBox 'Loop 5'
}

Func6() {
	MsgBox 'Loop 6'
}

Func7() {
	MsgBox 'Loop 7'
}

Func8() {
	MsgBox 'Loop 8'
}

Func9() {
	MsgBox 'Loop 9'
}

Func10() {
	MsgBox 'Loop 10'
}

Func11() {
	MsgBox 'Loop 11'
}

Func12() {
	MsgBox 'Loop 12'
}

Func13() {
	MsgBox 'Loop 13'
}

Func14() {
	MsgBox 'Loop 14'
}

Func15() {
	MsgBox 'Loop 15'
}

Func16() {
	MsgBox 'Loop 16'
}

Func17() {
	MsgBox 'Loop 17'
}

Func18() {
	MsgBox 'Loop 18'
}

Func19() {
	MsgBox 'Loop 19'
}

Func20() {
	MsgBox 'Loop 20'
}
vmech
Posts: 361
Joined: 25 Aug 2019, 13:03

Re: i need help how to random the loops not to be in order

01 May 2024, 05:06

@boiler
Why these extra movements?
Why are you ignoring Autohotkey's object-oriented features, such as the array of function objects?
Please post your script code inside [code] ... [/code] block. Thank you.
User avatar
boiler
Posts: 17193
Joined: 21 Dec 2014, 02:44

Re: i need help how to random the loops not to be in order

01 May 2024, 05:39

Rather than ask me why I didn’t do it that way, why not just demonstrate the way you suggest for OP to see? I’m not sure how what you’re saying is going to lead to shorter code. You still need to randomize the order they’re selected while ensuring is selected once and only once.
teadrinker
Posts: 4365
Joined: 29 Mar 2015, 09:41
Contact:

Re: i need help how to random the loops not to be in order

02 May 2024, 09:33

Perhaps @vmech meant something like this:

Code: Select all

arr := []
loop 20 {
	arr.Push(Func%A_Index%)
}
Loop 20 {
    arr.RemoveAt(Random(1, arr.Length))()
}
vmech wrote: object-oriented features
I wouldn't say that the function array is an object-oriented feature. It is rather the opposite, a feature from the functional approach.

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: mikeyww, WarlordAkamu67 and 45 guests