mardi 31 juillet 2018

Random name picker without duplication?

Im just creating the most simple name picker from a specified list. How should i modify it to dont duplicate the already "picked" names?

static void Main(string[] args) {

        string[] Names = { "Erik", "Levente", "Noel", "Áron", "Krisztián", "Kristóf", "Bence", "Roland", "Máté", "László", "Bálint" ,
        "Regina", "Brigitta", "Gréta", "Hédi", "Hanna", "Boglárka", "Jázmin", "Réka", "Alexandra", "Rebeka", "Lili", "Luca", "Zsófi"};

        Random rnd2 = new Random();
        Console.WriteLine("Az ID : '1' eszköz nyertese: " + Names[rnd2.Next(0, Names.Length - 1)]);

        Random rnd3 = new Random();
        Console.WriteLine("Az ID : '2' eszköz nyertese: " + Names[rnd2.Next(0, Names.Length - 1)]);

        Random rnd4 = new Random();
        Console.WriteLine("Az ID : '3' eszköz nyertese: " + Names[rnd2.Next(0, Names.Length - 1)]);

        Random rnd5 = new Random();
        Console.WriteLine("Az ID : '4' eszköz nyertese: " + Names[rnd2.Next(0, Names.Length - 1)]);

        Random rnd6 = new Random();
        Console.WriteLine("Az ID : '5' eszköz nyertese: " + Names[rnd2.Next(0, Names.Length - 1)]);

        Random rnd7 = new Random();
        Console.WriteLine("Az ID : '6' eszköz nyertese: " + Names[rnd2.Next(0, Names.Length - 1)]);


        Console.ReadKey(true);
    }




Aucun commentaire:

Enregistrer un commentaire