mercredi 19 août 2015

Randomize multidimensional array and avoid duplicates in C# [duplicate]

This question already has an answer here:

I have three lists. One with numers, one with names and the last one contain all the possible combinations of those two lists.

int[] cijfers = new int[13] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 };
string[] reeksen = new string[4] { "Schoppen","Harten","Klaveren","Ruiten" }; 
object[,] kaarten = new object[4, 13];


Random random = new Random();
        //Voor alle reeksen en bijhorende cijfers gaan we kaarten creëren
        for (int i = 0; i < reeksen.Length; i++) { 

            for (int j = 0; j < cijfers.Length; j++) { 

                //Opvullen van de array kaarten met kaarten
                kaarten[i,j]= random.Next(kaarten[0], kaarten[kaarten.Length])
               lbSerie1.Items.Add(kaarten[i, j] = reeksen[i].Substring(0, 1) + " " + cijfers[j]);

            }
        }

I now want them all to appear randomized in the listbox whitout any duplicates. Does anyone know a solution?

Thanks!




Aucun commentaire:

Enregistrer un commentaire