title: Very weird - code (with Random) works different when I use breakpoint
body: <p>I'm working on a neural networks project and I have 2 classes like this:</p>
  
  <pre><code>public class Net
  {
      // Net object is made of neurons
      public List&lt;Neuron&gt; Neurons = new List&lt;Neuron&gt;();
  
      // neurons are created in Net class constructor
      public Net(int neuronCount, int neuronInputs)
      {
          for (int n = 0; n &lt; neuronCount; n++)
          {
              Neurons.Add(new Neuron(n, neuronInputs));
          }
      }
  }
  
  public class Neuron
  {
      public int index; // neuron has index
  
      public List&lt;double&gt; weights = new List&lt;double&gt;(); // and list of weights
  
      // Neuron constructor is supposed to add random weights to new neuron
      public Neuron(int neuronIndex, int neuronInputs)
      {
          Random rnd = new Random();
  
          for (int i = 0; i &lt; neuronInputs; i++)
          {
              this.index = neuronIndex;
              this.weights.Add(rnd.NextDouble());
          }
      }
  </code></pre>
  
  <p>When I try to create network and display it's "contents":</p>
  
  <pre><code>Neuro.Net Network = new Neuro.Net(4, 4); // creating network with 4 neurons with 4 weights each
  
  // dgv is a DataGridView for weights preview
  dgv.Rows.Clear();
  dgv.Columns.Clear();
  
  // creating columns
  foreach (Neuro.Neuron neuron in Network.Neurons)
  {
      dgv.Columns.Add("colN" + neuron.index, "N" + neuron.index);
  }
  
  dgv.Rows.Add(Network.Neurons[0].weights.Count());
  
  for (int n = 0; n &lt; Network.Neurons.Count(); n++)
  {
     for (int w = 0; w &lt; Network.Neurons[n].weights.Count(); w++)
     {
         dgv.Rows[w].Cells[n].Value = Network.Neurons[n].weights[w];
     }
  }
  </code></pre>
  
  <p>When I run that code - <strong>I'm getting something like this</strong> (all weights are identical):</p>
  
  <p><img src="https://i.stack.imgur.com/VYCRd.png" alt="enter image description here"></p>
  
  <p>When I saw it - I tried to debug and find my mistake. However, <strong>when I put breakpoint in the neuron constructor</strong> - my network initializes as I want (weights are different):</p>
  
  <p><img src="https://i.stack.imgur.com/JZC0g.png" alt="enter image description here"></p>
  
  <p>I tried to use Debug and Release configurations - same results.</p>
  
  <p><strong>Can someone explain what is going on here?</strong></p>
  
  <p><strong>Magic?</strong></p>