1) Use
Sort to randomize the string before you split it. You will need to use
FileRead instead of
Loop, Read.
Code: Select all
MyArray := []
Test :=
(Join`r`n LTrim
"word;language
hello;english
ciao;italian
giasou;greek"
)
Sort, Test, Random
Loop, Parse, Test, `n, `r
MyArray.Push(StrSplit(A_LoopField, ";"))
for i, v in MyArray
s .= i "=" v[1] "," v[2] "`n"
MsgBox, % s
Or 2) Pull an item out of the array at random and insert it into a new array.
Code: Select all
MyArray := [], NewArray := []
Test :=
(Join`r`n LTrim
"word;language
hello;english
ciao;italian
giasou;greek"
)
Loop, Parse, Test, `n, `r
MyArray.Push(StrSplit(A_LoopField, ";"))
while MyArray.Haskey(1) {
Random, n, 1, MyArray.MaxIndex()
NewArray.Push(MyArray.RemoveAt(n))
}
for i, v in NewArray
s .= i "=" v[1] "," v[2] "`n"
MsgBox, % s
Edit: Or 3) Use
InsertAt to insert an item at a random index (between
1 and
MyArray.MaxIndex() + 1).
Code: Select all
MyArray := []
Test :=
(Join`r`n LTrim
"word;language
hello;english
ciao;italian
giasou;greek"
)
Loop, Parse, Test, `n, `r
{
if (A_Index = 1) ; Insert the first one at MyArray[1]
MyArray[1] := StrSplit(A_LoopField, ";")
else { ; Insert at a random index
Random, n, 1, MyArray.MaxIndex() + 1
MyArray.InsertAt(n, StrSplit(A_LoopField, ";"))
}
}
for i, v in MyArray
s .= i "=" v[1] "," v[2] "`n"
MsgBox, % s
Edit2: I suggest #1.