Drop links or images here to add them to the editor.

A random name generator.

★☆☆

A random name generator can be useful for creating dummy data for test purposes.

School club

Make

Write a program to output a random name from one list of forenames and another list of surnames.

Success Criteria

Remember to add a comment before a subprogram, selection or iteration statement to explain its purpose.

Complete the subprogram called generate_name that:

  1. Assigns an array of forenames. You can use the names: Muhammad, Noah, Jack, Lily, Sophia, Olivia or some of your own.
  2. Assigns an array of surnames. You can use the names: Wang, Smith, Devi, Jones, Kim and Rodríguez or some of your own.
  3. It returns a random forename with a space and a random surname.

Complete the main program so that:

  1. It runs an interactive loop: each empty input prints a new random name, and the input end ends the program.

Typical inputs and outputs from the program would be:

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 end to quit.

🆘 If you're really stuck, use this Parsons code sorting exercise
Complete program
// 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());
---
            }
---
        }
---
    }
---
}