Public Class Tester
Public Shared Sub Main
Dim arrayShuffle() As String = {"A", "B", "C", "D", "E"}
For Each fruit As String In arrayShuffle
Console.WriteLine(fruit)
Next fruit
Shuffle(arrayShuffle)
For Each fruit As String In arrayShuffle
Console.WriteLine(fruit)
Next fruit
End Sub
Public Shared Sub Shuffle(ByRef shuffleArray() As Object)
Dim counter As Integer
Dim newPosition As Integer
Dim shuffleMethod As New Random
Dim tempObject As Object
For counter = 0 To shuffleArray.Length - 1
newPosition = shuffleMethod.Next(0, shuffleArray.Length - 1)
tempObject = shuffleArray(counter)
shuffleArray(counter) = shuffleArray(newPosition)
shuffleArray(newPosition) = tempObject
Next counter
End Sub
End Class
|