lundi 3 avril 2017

Generating 8 unique random numbers C#

static int[] RandomDraw()
    {
        int Min = 1;
        int Max = 45;

        int[] test2 = new int[8];

        Random randNum = new Random();
        for (int i = 0; i < test2.Length; i++)
        {
            test2[i] = randNum.Next(Min, Max);               
        }
        return test2;
    }

This generates 8 numbers between 1 and 45, but I can't seem to find an easy solution to making sure that each number is unique. Any help is appreciated.




Aucun commentaire:

Enregistrer un commentaire