RosettaCodeData/Task/Knuth-shuffle/AutoHotkey/knuth-shuffle-2.ahk
2023-07-01 13:44:08 -04:00

17 lines
289 B
AutoHotkey

toShuffle:=[1,2,3,4,5,6]
shuffled:=shuffle(toShuffle)
;p(toShuffle) ;because it modifies the original array
;or
;p(shuffled)
shuffle(a)
{
i := a.Length()
loop % i-1 {
Random, j,1,% i
x := a[i]
a[i] := a[j]
a[j] := x
i--
}
return a
}