Shuffle a string in VB.Net

 

In this tutorial/code example I’m going to show you a method to shuffle the contents of a string. You might use this for something like an anagram game.

Private ran As New Random

Private Function randomizeString(ByVal input As String) As String
Dim rtn As String = ""
Dim i As Integer

While input.Length > 0
    i = ran.Next(0, input.Length)
    rtn &= input.Substring(i, 1)
    input = input.Remove(i, 1)
End While

Return rtn
End Function