Visual Basic Randomly Shuffle a List

Here is an example of randomly shuffling an object of type List in Visual Basic.

Module ModuleTest Sub Main() Dim myList As List(Of Integer) = New List(Of Integer)() myList.Add(1) myList.Add(2) myList.Add(3) myList.Add(4) myList.Add(5) myList = myList.OrderBy(Function(a) System.Guid.NewGuid()).ToList() For Each item In myList Console.WriteLine(item) Next Console.ReadLine() End Sub End Module

In the example above, we create our object named myList and add 5 elements. Then we randomly shuffle our list with "OrderBy(Function(a) System.Guid.NewGuid())" and print it on the screen.



You May Interest

Visual Basic String Making Lowercase

Visual Basic Get Now

How to Find the Name of the Operating System in Visual Basic ?

Visual Basic Finding the Computer Name

Visual Basic Getting Last Character of String