A random name generator.
★☆☆A random name generator can be useful for creating dummy data for test purposes.
Write a program to output a random name from one list of forenames and another list of surnames.
Remember to add a comment before a subprogram, selection or iteration statement to explain its purpose.
generate_name that:end ends the program.Press Enter to generate a new name, or input 'end' to quit.
Lily Rodríguez
Sophia Devi
end
Send an empty line of stdin to generate a name, and
endto quit.
// Random name generator program
using System;
class Submission
{
---
// -------------------------
// Globals
// -------------------------
// Random number generator (one for the whole program)
static Random random_generator = new Random();
// -------------------------
// Subprograms
// -------------------------
// Function to return a random name
---
static string generate_name()
{
---
string[] forename_list = {"Muhammad", "Noah", "Jack", "Lily", "Sophia", "Olivia"};
string[] surname_list = {"Wang", "Smith", "Devi", "Jones", "Kim", "Rodríguez"};
string forename = forename_list[random_generator.Next(0, 6)];
string surname = surname_list[random_generator.Next(0, 6)];
return forename + " " + surname;
---
}
---
// -------------------------
// Main program
// -------------------------
public static void Main(string[] args)
{
---
Console.WriteLine("Press Enter to generate a new name, or input 'end' to quit.");
---
string wait = "";
while (wait != "end")
{
---
wait = Console.ReadLine();
if (wait != "end")
{
---
Console.WriteLine(generate_name());
---
}
---
}
---
}
---
}