Q:

Visual Basic Random Name Generator function

Ok, working with Visual Basic (in Visual Studio Express 2013, if that makes a difference). I'm trying to create a function that takes a list of first names from a text file, and inserts each line into an index in an array. What I'm getting is the particular index, rather than the string assigned to that index.
    Private Sub btnAutofill_Click(sender As Object, e As EventArgs) Handles btnAutofill.Click

        Dim ranFname As String = RandomFname(ranFname)
        Dim ranLname As String = RandomLname(ranLname)

        txtCustFname.Text = ranFname
        txtCustLname.Text = ranLname

    End Sub

    Private Function RandomFname(ByRef ranFname As String) As String

        Dim userPath As String = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)
        Dim fname() As String
        Dim rand As New Random()

        fname = IO.File.ReadAllLines(userPath & "\OneDrive\Coding\Visual Studio\firstNames.txt")
        ranFname = rand.Next(0, fname.Length - 1)
        Return ranFname

    End Function

    Private Function RandomLname(ByRef ranLname As String) As String

        Dim userPath As String = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)
        Dim lname() As String
        Dim rand As New Random()
        lname = IO.File.ReadAllLines(userPath & "\OneDrive\Coding\Visual Studio\lastNames.txt")
        ranLname = rand.Next(0, lname.Length - 1)
        Return ranLname

    End Function

Now, when I click the button for autofill, instead of my textboxes having:
First Name: Mary   Last Name: Jones
I get:
First Name: 68   Last Name: 68
I also dont know why it's making it the same number every time, it should be random.
So obviously, I'm on the wrong track. Somebody mind helping me out?

A:

ReadAllLines() returns an array, you just want a random position from this array:
Private Function RandomFname(ByRef ranFname As String) As String

    Dim userPath As String = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)
    Dim fname() As String
    Dim rand As New Random()

    fname = IO.File.ReadAllLines(userPath & "\OneDrive\Coding\Visual Studio\firstNames.txt")
    Return fname(rand.Next(0, fname.Length - 1))

End Function

I also dont know why it's making it the same number every time, it should be random.
If you want a different number each time, instantiate a single Random once that both methods use, or instantiate each Random with the overload that allows you to supply your own seed:
Dim rand As New Random(DateTime.Now.Millisecond)

