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 Using String ToCharArray

Visual Basic Generating Random Letters

Visual Basic Powering a Number

Visual Basic Reverse Array

Visual Basic Getting Last Character of String