mercredi 24 février 2016

Create number for random and non repeat

i'm code:

       Random rand = new Random();
       int[] arr = new int[4];
       for (int i = 0; i < 4; i++)
       {
           for (int k = 0; k < 4; k++)
           {
               int rad = rand.Next(1, 5);
               if (arr[k] != rad)
                   arr[i] = rad;
           }
       }
       for (int i = 0; i < 4; i++)
           MessageBox.Show(arr[i].ToString());

I wanna production numbers from 1 to 4 am and unequal with each other. tnx.




Aucun commentaire:

Enregistrer un commentaire