-2

I have searched around for a solution but I just cannot understand those complicated-detailed algorithms as i'm fairly new in c# and right now i'm trying to create this program. I want the random number generator to generate 1 to 4 and it wont repeat the same number to 4 different textbox but when i executed the code as below:-

        Random random = new Random();
        var numberNo = Enumerable.Range(1, 4);
        var shuffled = numberNo.OrderBy( a => random.NextDouble());
        txtrnd1.Text = String.Join("",shuffled);
        txtrnd2.Text = String.Join("",shuffled);
        txtrnd3.Text = String.Join("",shuffled);
        txtrnd4.Text = String.Join("",shuffled);

the result that i obtained is (for the 4 textbox : textbox1 will display "1342" ,textbox2 will display "1234" etc) in the textbox but what i want for the result for the 4 textbox is (for example textbox1 will display "1" textbox2 will display "2" etc) in the 4 different textbox so that i can compare it with the user input which i did it in another program of mine

        int intrandomnumber1;
        Random randomnumber = new Random();
        intrandomnumber1 = randomnumber.Next(1, 10);
        userinput1.Text = Convert.ToString(intrandomnumber1);

appreciate any help and thanks in advance!

Rune
  • 1
  • 2

1 Answers1

0

If you look at the text in each textbox, you'll notice that they all contain a full list of 1-4, randomly permutated. Therefore, you should iterate through shuffled once to get your list.

The easiest way would be to create a System.Collections.Generic.List<int> from the enumerable:

List<int> shuffledList = new List<int>(shuffled);
Drew McGowen
  • 11,471
  • 1
  • 31
  • 57