2020年9月1日 星期二

vb.net 隨機更換ArrayList的順序 [Random ArrayList Index]

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
    Private Function RandomSort(aryInfo As ArrayList) As ArrayList
        Dim sortedList As ArrayList = New ArrayList()
        Dim generator As Random = New Random()

        Do While aryInfo.Count > 0
            Dim position As Integer = generator.Next(aryInfo.Count - 1)
            Dim strInfo As String = Trim(aryInfo(position))
            strInfo = strInfo.Replace(vbCrLf, "")
            strInfo = strInfo.Replace(vbLf, "")
            If strInfo <> "" Then sortedList.Add(strInfo)
            aryInfo.RemoveAt(position)
        Loop

        Return sortedList
    End Function

沒有留言:

張貼留言