Need to open text file of first name and grab name at random

Joined
Apr 13, 2011
Messages
19
Programming Experience
Beginner
This one is a tricky one for me.

I have a text file that includes a list of first names, each on their own separate line.

What I am trying to do is to find a way to click on my button and have my app open the list and randomly grab a name and place it into a textbox.

I would include some code but I'm not even sure where to begin.

I'm thinking that I will need to code the button to use the openfiledialog..create an algorithm to use a random copy line and return it into the textbox.

What do you guys think?
 
I'm thinking that I will need to code the button to use the openfiledialog
Only if you don't know the location of the file.


create an algorithm to use a random copy line
Load the lines in a List(Of String) with a StreamReader and your algorithm is as simple as: aRandomInstance.Next(list.Count)

If you need to repeat the random picking of a name, you could shuffle the list once.
 
Back
Top