Android Question Randomize the list

Hi, i have a List and i want to Randomize my List
For example my List content is :
B4X:
    Dim listview As ListView
Dim list As List
list.Initialize
list.Add("Banana")
list.Add("home")
list.Add("car")
list.Add("cat")
list.Add("B4a")

For i = 0 To list.Size -1
    listview.AddSingleLine(list.Get(i))
Next
I want to randomly move items from my list
Is there any code?
 
Last edited:

Brian Dean

Well-Known Member
Licensed User
Longtime User
I want to randomly move items from my list

If you mean that you want to select items from the list in random order then use something like this ...

B4X:
Private Sub getRandomItem(input As List) As String
    If (input.Size < 1) Then Return ""
    Dim i As Int = Rnd(0, input.Size)
    Dim selection As String = input.Get(i)
    input.RemoveAt(i)
    Return selection
End Sub

The list will be progressively destroyed, so use a copy of your real list.
 
Upvote 0
Top