tags:

views:

18

answers:

2

Hi,

I use the following statement to shuffle the data in a range (for example 1 to 10) and result is stored in a combo box.

            Dim RndSQs As New Random()
            Dim ArNumbersSQs As Integer() = Enumerable.Range(1, Val(txtSQs.Text)).OrderBy( _

                       Function(x) RndSQs.Next()).ToArray()

            Dim iSQs = 0

            For iSQs = 0 To Val(txtSQs.Text) - 1

                cmbSQs.Items.Add(ArNumbersSQs(iSQs))

            Next iSQs

How can I shuffle that data which is already in a combo box but not in a range. These nos. can be random no. that user shall chose.

Please guide.......

A: 
Enumerable.Range(1, Val(txtSQs.Text))

Generates the range, and can be replaced by any IEnumerable. For example, if you had a List(Integer) called lst of numbers, you could write:

lst.OrderBy(Function(x) RndSQs.Next()).ToArray()
Lou Franco
A: 

In general, to shuffle an array you could provide a custom sorter:

    Dim random As New Random()
    Array.Sort(elements, Function() As Integer
                               Return random.Next
    End Function)
vulkanino