Bonjour,
j'ai besoin de créer un tableau de 10 nombre random, compris entre 0 et 10, sans redondance.
Cependant, je n'arrive jamais à obtenir 0 comme valeur dans mon tableau.


Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
int currentQ;
            int[] tab_random = new int[11];
            bool existe;
            for (int i = 0; i <= 11; i++)
            {
                Random rand = new Random();
                existe = true;
                currentQ = rand.Next(0,11);
                while (existe == true)
                {
                    existe = false;
                    for (int y = 0; y <= i; y++)
                    {
 
                        if (currentQ == tab_random[y])
                        {
                            existe = true;
                            currentQ = rand.Next(0,11);
                        }
                    }
                }
                tab_random[i] = currentQ;
                Console.WriteLine(currentQ.ToString());
 
            }