dimanche 14 juin 2020

How to pick a random string from random array

I've picked a random array of 10 from 28, now I am trying to pick a random 1 from the 10 but can't seem to figure out how. Here's my code:

            Random rand = new Random();



        int[] array = new int[10];
        int count = 0;


        for (int i = 0; i < array.Length; i++)
        {
            int final = rand.Next(28);
            while (final == array[0] || final == array[1] || final == array[2] || final == array[3] || final == array[4] || final == array[5] || final == array[6] || final == array[7] || final == array[8] || final == array[9])
            {
                final = rand.Next(10);

            }
            array[i] = final;
            count++;
            Console.WriteLine($"#{count} player {array[i]}");
            string finalists = names[final].firstname.ToString();
            Console.WriteLine($"Finalist: {finalists}");
            Thread.Sleep(2000);

        }

thanks so much for any help




Aucun commentaire:

Enregistrer un commentaire