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 Reverse Array

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

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

Visual Basic Remove Element from Array