samedi 10 décembre 2022

I'm generating a list of 100 random "names", now I need to follow it up with 100 more names and 100 random numbers. C#

I'm making a program that generates the "names" (random lines of text from the ASCII) that are the names of movies in this instance. I should follow them up with a "name" of a director for each (can also be generated from the ASCII), and after that the random year that is the year the "movie" was made (from 1896 to 2021).

I have two separate functions that randomize the names of the movies and directors, but I'm confused with the supposed placement of the Console.Writeline which the intelligence only allows inside their own loops. Otherwise it doesn't seem to be able to use the values "directorname" and "moviename".

I need it to write the names in a single line, ai. (KHGTJ, KGHTJF).

Also I need a way to generate a random year from 1896 to 2021 that is printed after the names of the movie, and director, ai. (KFJU, MDDOS, 1922).

private static void GenerateRandomNames()
        {
            Random random = new Random();
            char y = (char)65;

            for (int p = 0; p < 100; p++)
            {
                string directorname = "";
                for (int m = 0; m < 5; m++)
                {
                    int b = random.Next(65, 90);
                    y = (char)b;
                    directorname += y;
                }
                Console.WriteLine(directorname);
            }

            Random rnd = new Random();
            char x = (char)65;

            for (int j = 0; j < 100; j++)
            {
                string moviename = "";
                for (int i = 0; i < 5; i++)
                {
                    int a = rnd.Next(65, 90);
                    x = (char)a;
                    moviename += x;

                }
                Console.WriteLine(moviename);
            }
            Console.WriteLine();

I need to fix the plecement of the Console.Writeline() so it can print both names in the same line, and be able to print the year after them.

I've tried placing the Console.Writeline() outside the loops, but of course it can't then use the name. But this way it prints them the wrong way.




Aucun commentaire:

Enregistrer un commentaire