0

I want to make a math app in windows forms and I want to display 4 random numbers in 4 textboxes but when I use:

 Random randomNumitor1 = new Random();
        int rndmNMT1 = randomNumitor1.Next(1, 10);
        textBox2.Text = rndmNMT1.ToString();
        Random randomNumitor2 = new Random();
        int rndmNMT2 = randomNumitor2.Next(1, 10);
        textBox4.Text = rndmNMT2.ToString();
        Random randomNumarator1 = new Random();
        int rndmNMRT1 = randomNumarator1.Next(1, 10);
        textBox1.Text = rndmNMRT1.ToString();
        Random randomNumarator2 = new Random();
        int rndmNMRT2 = randomNumarator2.Next(1, 10);
        textBox3.Text = rndmNMRT2.ToString();

the app is generating the 4 same numbers. Can somebody help me to modify this code to display 4 different numbers. I want to say I will use it for a fraction resolving exercise. Help me please!

  • 1
    Does this answer your question? [Random number generator only generating one random number](https://stackoverflow.com/questions/767999/random-number-generator-only-generating-one-random-number) – James Thorpe Oct 07 '20 at 14:43

1 Answers1

1

Don't create a new Random(), but use the same Random() instead.

Suprisingly, using randomNumitor1 these 4 times will result in different numbers.

Steven
  • 1,996
  • 3
  • 22
  • 33
  • WOOOOOOW! IT IS WORKING! :)) Thank you, man! You were so quick! Have a great day! –  Oct 07 '20 at 14:47