I am having problem with random number generation in c#. If I RUN this form application directly, the random number generation is same for all.
If i DEBUG this line by line by pressing F10, then it will generate different random numbers. Why this is happening? What should I do to generate different random numbers?
Greyhound.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace ADayAtTheRaces
{
class Greyhound
{
int location=0;
Random randomize = new Random();
public int run()
{
location = randomize.Next(0, 100);
return location;
}
}
}
Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace ADayAtTheRaces
{
public partial class Form1 : Form
{
Greyhound[] greyHound = new Greyhound[4];
ProgressBar[] progressBar = new ProgressBar[4];
public Form1()
{
InitializeComponent();
for (int i = 0; i < 4; i++)
{
greyHound[i] = new Greyhound();
}
}
private void button1_Click(object sender, EventArgs e)
{
for (int i = 0; i <= 3; i++)
{
progressBar[i].Value = greyHound[i].run();
}
}
}
}