jeudi 2 juillet 2015

Compare All Elements in An Array [duplicate]

This question already has an answer here:

I'm sure this has an easy solution, but I keep finding things that are more complicated than what I need.

I have an array that gets filled with randomly generated numbers. I don't want any of the numbers to be the same, so I want to compare each new element with each old element, and re-randomize the new element if it's equal to an old one.

Here's how I'm populating the array with a Random named rand.

for (int i = 0; aSet.Length > i; i++)
        {
            if (i == 5)
            {
                aSet[i] = rand.Next(1, 16);
            }
            else
            {
                aSet[i] = rand.Next(1, 76);

            }
        }




Aucun commentaire:

Enregistrer un commentaire