I am attempting to shuffle an array of strings, below is the segment of code i have already. However, a problem with this code is that alot of the times it shuffles the content but excludes one value. e.g shuffling A, B, C, D it will do this: A, D , , C.
Any help would be greatly appreciated.
Private rnd = New Random()
Public Sub Shuffle(ByRef List() As String)
Dim Limit As Integer = List.Length - 1
For i = Limit To 0 Step -1
Dim j As Integer = rnd.Next(0, i + 1)
Dim temp As String = List(i)
List(i) = List(j)
List(j) = temp
Next
End Sub
Dim j As Integer = rnd.Next(0, Limit + 1)not sure if it is related but you want to make sure each element is considered for swap at least onceList), but your problem has most likely to do with the fact that the list contains a blank value which is being included in the shuffling.