vb.net randomizer

how can I make a little tool that can randomize a text file I have..
for example I have some ids like this


Im looking for a way to have it change and be all random.. how can I do this?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Fernando SotoRetiredCommented:

The following subroutine will do what you want to do.

Private Sub RandomizeLines(inputPath As String, outputPath As String)

    ' Read all lines from file with ID's into memory, List object
    Dim lines As List(Of String) = File.ReadAllLines(inputPath).ToList()
    ' Get the number of line read
    Dim count As Integer = lines.Count()
    ' Array to hold randomized lines
    Dim linesRand() As String = New String(count - 1) {}
    ' Get a random number generator
    Dim rand As Random = New Random(DateTime.Now.Millisecond)

    ' For each line of the input file
    For Each line In lines
        ' Get a random number between 0 and max lines in file
        Dim idx As Integer = rand.Next(0, count - 1)
        ' Check to see if array slot is empty if not get a nuw random number
        While linesRand(idx) IsNot Nothing
            idx = rand.Next(0, count)
        End While
        ' Fill the empty slot with a line
        linesRand(idx) = line

    ' Write the array out to the file system
    File.WriteAllLines(outputPath, linesRand)

End Sub

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.