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 Powering a Number

Visual Basic Remove Element from Array

Visual Basic Non-Restart Check If Application is Open

Visual Basic Reverse Array

Visual Basic How To Find The Average Of 10 Numbers Using A While ...