Re: Random listbox item selection



On Dec 21, 3:56 pm, Family Tree Mike
<FamilyTreeM...@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
As your code seems a class library type, i optimized as to be used in
a executable but no help:

Dim r As New Random
Dim idx As Integer
Dim loi As New System.Collections.Generic.List(Of Integer)

If loi.Count = ListBox1.Items.Count Then
MsgBox("All have been selected...")

End If

idx = r.Next(0, ListBox1.Items.Count)

While loi.Contains(idx)
idx = r.Next(0, ListBox1.Items.Count)
End While

ListBox1.SelectedIndex = idx
loi.Add(idx)

Still, the selection goes endless,never ends. Once an item selected,
this(same) item is being selected somehow in next random selection.

I suspect that is because the List (Of Integer) is reset each time into the
subroutine. That is why I made it a class member. It is getting recreated
on each entry into the routine.

I didn't like this random selection algorithm, it doesn't do %100 what
i wanted. As i stated in my previous post, a listbox item must be
selected for once consecutively, the next random item selection must
NOT be the previous one(self). My aim was a random list like playing
songs randomly(shuffle) in Windows Media Player which stops at the end
of random selection and which doesn't select same item more than once
in random(shuffle) mode.

Anyway thanks Mike for striving on this issue.
.