Hi everyone, been stuck on this for a few days now and cant wrap my head around it.
I need to take a random amount of lines from each txt file and keep a count on how many have been picked. Done that but now i need to shuffle the two lists in to 1 list and then add to a list view.
Am able to shuffle each list seperately and add to listview however 1.txt list shows above 2.txt where i want them shuffled again together.
Any help with this would be great, am sure its simple as am adding to a list from text file and shuffling already but just cant seem to figure it out for both lists
Thanks
I need to take a random amount of lines from each txt file and keep a count on how many have been picked. Done that but now i need to shuffle the two lists in to 1 list and then add to a list view.
Am able to shuffle each list seperately and add to listview however 1.txt list shows above 2.txt where i want them shuffled again together.
Any help with this would be great, am sure its simple as am adding to a list from text file and shuffling already but just cant seem to figure it out for both lists
Thanks
B4X:
Sub Process_Globals
Dim playlist As List
End Sub
Sub Globals
Private ListView1 As ListView
Private NewList1 As List
Private NewList2 As List
Private RndNo1 As Int = Rnd(1,10)
Private RndNo2 As Int = Rnd(1,10)
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("main")
playlist.Initialize
Populate1
End Sub
Sub Populate1
Dim lSize As Int = RndNo1
Dim nrMin As Int = 1
Dim nrMax As Int = 10
Dim llist As List = GetRndNonRepeatingList(lSize, nrMin, nrMax)
Dim AddLine As String
Log(RndNo1&" Selected: ")
Log(RndNo2&" Selected: ")
NewList1 = File.ReadList(File.DirAssets,"1.txt")
NewList2 = File.ReadList(File.DirAssets,"2.txt")
For Each n As Int In llist
'Log(AddLine)
'Log(n)
AddLine = NewList1.Get(n)
NewList1 = ShuffleList(NewList1)
ListView1.AddSingleLine(AddLine)
Next
Dim lSize2 As Int = RndNo2
Dim nrMin2 As Int = 1
Dim nrMax2 As Int = 10
Dim llist2 As List = GetRndNonRepeatingList(lSize2, nrMin2, nrMax2)
Dim AddLine2 As String
For Each n As Int In llist2
AddLine2 = NewList2.Get(n)
NewList2 = ShuffleList(NewList2)
ListView1.AddSingleLine(AddLine2)
Next
End Sub
Sub ShuffleList(pl As List) As List
For i = pl.Size - 1 To 0 Step -1
Dim j As Int
Dim k As Object
j = Rnd(0, i + 1)
k = pl.Get(j)
pl.Set(j,pl.Get(i))
pl.Set(i,k)
Next
Return pl
End Sub
Sub GetRndNonRepeatingList(lSize As Int, rnMin As Int, rnMax As Int) As List
Dim llist As List
Dim nr As Int
llist.Initialize
Private nNativeMe As JavaObject
nNativeMe.InitializeContext
If rnMax+1>=lSize And rnMin<rnMax Then
Do While llist.Size< lSize
nr=nNativeMe.RunMethod("GetRndJAVAInt", Array(rnMin,rnMax))
If llist.IndexOf(nr)=-1 Then
llist.Add(nr)
End If
Loop
End If
Return llist
End Sub
#If JAVA
import java.util.Random;
public static int GetRndJAVAInt(int min, int max) {
Random random = new Random();
return random.nextInt((max - min) + 1) + min;
}
#End If