title: random number generation:returning same number in C# if I run. alright if Debug step by step
body: <p>I am having problem with random number generation in c#. If I <strong>RUN</strong> this form application directly, the random number generation is same for all.</p>
  
  <p>If i <strong>DEBUG</strong> 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?</p>
  
  <blockquote>
    <p>Greyhound.cs</p>
  </blockquote>
  
  <pre><code>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;
          }
      }
  }
  </code></pre>
  
  <blockquote>
    <p>Form1.cs</p>
  </blockquote>
  
  <pre><code>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 &lt; 4; i++)
              {
                  greyHound[i] = new Greyhound();
              }
          }
  
          private void button1_Click(object sender, EventArgs e)
          {
              for (int i = 0; i &lt;= 3; i++)
              {
                  progressBar[i].Value = greyHound[i].run();
              }
          }
      }
  }
  </code></pre>