Knuth shuffle: Difference between revisions

(Added Wren)
Line 795:
s .= "," . a%A_Index%
Return SubStr(s,2) ; drop leading comma
}</lang>
 
For Arrays:
 
[https://www.autohotkey.com/boards/viewtopic.php?f=6&t=79152 to MsgBox it, you can use p()]
 
[https://stackoverflow.com/questions/6274339/how-can-i-shuffle-an-array#6274381 (translated from)]
<lang AutoHotkey>shuffled:=shuffle([1,2,3,4,5,6])
;p(shuffled)
shuffle(a)
{
length:=a.Length()+1
loop % length-2 {
Random, j,1,% length
length--
x := a[length]
a[length] := a[j]
a[j] := x
}
return a
}</lang>
 
Anonymous user