Hello Guys,
I have the following code to shuffle LIST1 into LIST2, but at the end both lists are shuffled. I want LIST1 as it was originally.
What am I doing wrong?
Regards,
Fernando
I have the following code to shuffle LIST1 into LIST2, but at the end both lists are shuffled. I want LIST1 as it was originally.
What am I doing wrong?
B4X:
Dim lstWords1, lstWords2 As List
lstWords1 = Array("AVIÃO", "BOLA", "CASA", "COPO", "DADO", "FACA", "FLOR", "FOGO", "FOTO", "GATO", "LEÃO", "MALA", "MENINA", "MENINO", "QUEIJO", "SUCO", "TREM", "XÍCARA", "CÂMARA")
' lstWords1 = File.ReadList(File.DirAssets, "tabpalavras.txt")
Log("LIST1 before shuffle: " & lstWords1)
lstWords2.Initialize2(ShuffleList(lstWords1))
Log("LIST2 after shuffle: " & lstWords2)
Log("LIST1 after shuffle: " & lstWords1)
Sub ShuffleList(StList As List) As List
Dim wElement As String
Dim wIndex As Int
For i = 0 To StList.size - 1
wIndex = Rnd(i, StList.size)
wElement = StList.get(i)
StList.set(i, StList.get(wIndex))
StList.set(wIndex, wElement)
Next
Return StList
End Sub
Regards,
Fernando