I am trying to make a random name generator method that will create a random first and last name from a list of names I have stored in two separate text files. (First Name.txt && LastName.txt)
So essentially I want to select a random token from the text file and match it from a random token from the last name text file:
I'm just not sure how I can manipulate the string names into a respective random integer.
private static void selectName(Scanner firstName, Scanner lastName) {
// Initialization of Variables
String randomFirstName = null;
Random rand = new Random();
int randomName = rand.nextInt(199) + 1; // 1 - 200
while (firstName.hasNext()) {
randomFirstName = firstName.next();
}
} // closes FileInformation
The other idea I could think of was to store the contents into an array and transverse that way? Would that be the best way or is there a way to do it as I have now?
Aucun commentaire:
Enregistrer un commentaire