Reputation:
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!
Upvotes: 0
Views: 52
Reputation: 2122
Don't create a new Random(), but use the same Random() instead.
Suprisingly, using randomNumitor1
these 4 times will result in different numbers.
Upvotes: 1