lundi 31 mai 2021

Randomly select two items from an array and then remove them from the array, and randomly select one item from two already randomly selected items c# [duplicate]

I know this has probably been asked before but all the answers i could find i didn't know how to apply to my code.

here is my code

string[] teams = { "Team 1", "Team 2", "Team 3", "Team 4", "Team 5", "Team 6", "Team 7", "Team 8" };
        Console.WriteLine("The available teams are: ");
        for (int i = 0; i < teams.Length; i++)

        {
            Console.WriteLine(teams[i]);
        }

        Random rnd1 = new Random();
        int r1 = rnd1.Next(teams.Length);
        Random rnd2 = new Random();
        int r2 = rnd2.Next(teams.Length);
        Console.WriteLine("Round 1: " + teams[r1] + " vs " + teams[r2]);

How can I make it so that the two teams will always be different, and so that I can do a Round 2 which will be another two different teams.

Another thing that I need to do is to make it so that when the two teams are picked for a round (let's say it's Team 3 and Team 7) to randomly select out of those two teams so i can decide a winner. I've tried a bunch of things and none of it worked, I mostly need help with the first problem but if anyone can help with the second one as well that'd be appreciated




Aucun commentaire:

Enregistrer un commentaire