Is there an easy way to randomize a list in VB.NET?

后端 未结 8 1423
无人及你
无人及你 2020-12-02 00:35

I have a list of type System.IO.FileInfo, and I would like to randomize the list. I thought I remember seeing something like list.randomize() a li

8条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-02 01:07

    Dim oRand As New Random() 'do not seed!!!!
    Private Sub GetRandom(ByRef currentVals As List(Of Integer))
        Dim i As New List(Of Integer), j As Integer
        For x As Integer = 0 To currentVals.Count - 1
            j = oRand.Next(0, currentVals.Count)
            i.Add(currentVals(j))
            currentVals.RemoveAt(j)
        Next
        currentVals = i
    End Sub
    

提交回复
热议问题