title: Sometimes list doesn't get initialized
body: <p><strong>SOLVED: I figured it out myself. I can't select my answer for 2 days. Thank you everyone!</strong></p>
  
  <p>I have this weird bug. Sometimes my list is 0, when I can't see why. Every time I stepped through the debugger, it worked. It's making me crazy. Please help! This is travelling salesperson branch and bound, by the way.</p>
  
  <pre><code> public static BSSFPair generateBSSF(ref City[] Cities, int numberOfTrials)
      {
          int n = Cities.Length;
  
          //Declare variable for updating.
          double minCostOfBSSF = double.PositiveInfinity;
          List&lt;int&gt; minRandomCityOrder = new List&lt;int&gt;();
  
          //Try many random paths, and keep track of the minimum-cost path. Then select the minimum-cost path as the BSSF.
          for (int iteration = 0; iteration &lt; numberOfTrials; iteration++)
          {
              //Choose a random path.
              List&lt;int&gt; randomCityOrder = new List&lt;int&gt;(generateRandomOrderInts(n)); //a list of ints of cities. Each city int only occurs once.
  
              //Determine cost of route using the TSPSolution class.
              System.Collections.ArrayList cities = new System.Collections.ArrayList(); //a list of City objects
              foreach (int i in randomCityOrder)
              {
                  cities.Add(Cities[i]);
              }
              ProblemAndSolver.TSPSolution bssf = new ProblemAndSolver.TSPSolution(cities);
              double costOfBSSF = bssf.costOfRoute();
  
              //Update the minimums.
              if (costOfBSSF &lt; minCostOfBSSF)
              {
                  minCostOfBSSF = costOfBSSF;
                  minRandomCityOrder = new List&lt;int&gt;(randomCityOrder);
              }
          }
  
          //return the path and the cost of the BSSF.
  
  //&lt;---- This is where the method with the bug was called.
  
          return new BSSFPair(minCostOfBSSF, convertCityListToEdges(minRandomCityOrder)); //&lt;---- THIS IS WHERE THE METHOD WITH THE BUG WAS CALLED.
      }
  </code></pre>
  
  <p><strong>This method is where the error happens:</strong></p>
  
  <pre><code>    /// &lt;summary&gt;
      /// Converts a list of cities (WITHOUT THE LAST CITY BEING A DUPLICATE OF THE FIRST CITY) to a list of edges
      /// (WITH THE LAST EDGE GOING BACK TO THE START OF THE FIRST EDGE because it wraps around so you can easily draw it).
      /// &lt;/summary&gt;
      /// &lt;param name="minRandomCityOrder"&gt;&lt;/param&gt;
      /// &lt;returns&gt;&lt;/returns&gt;
      public static List&lt;Edge&gt; convertCityListToEdges(List&lt;int&gt; minRandomCityOrder)
      {
          if(minRandomCityOrder.Count &lt; 2)
          {
  
  //Right here-&gt;
  
              throw new NotImplementedException();  //&lt;------- RIGHT HERE. minRandomCityOrder count is 0. How did that happen?
          }
          int n = minRandomCityOrder.Count;
          //Convert the BSSF path to a list of edges.
          List&lt;Edge&gt; newBssfPath = new List&lt;Edge&gt;();
          int prev = minRandomCityOrder[0];
          for (int i = 1; i &lt; n; i++)
          {
              newBssfPath.Add(new Edge(prev, minRandomCityOrder[i]));
              prev = minRandomCityOrder[i];
          }
          //Add edge from end to start.
          newBssfPath.Add(new Edge(minRandomCityOrder[n - 1], minRandomCityOrder[0]));
  
          return newBssfPath;
      }
  </code></pre>
  
  <p>Utility function called by the code below. I've tested this myself, and it never returns an empty list.</p>
  
  <pre><code>    /// &lt;summary&gt;
      /// Generate a list of ints in the range [0, (maximum-1)] (Inclusive) in a random order. Each int occurs only once in the list.
      /// &lt;/summary&gt;
      /// &lt;param name="maximum"&gt; "maximum" is the upper bound, and is not included in the list.&lt;/param&gt;
      /// &lt;returns&gt;the random-ordered list.&lt;/returns&gt;
      private static List&lt;int&gt; generateRandomOrderInts(int maximum)
      {
          if (maximum &lt; 1)
          {
              throw new NotImplementedException();
          }
          Random random = new Random();
          List&lt;int&gt; intsToAdd = new List&lt;int&gt;();
          List&lt;int&gt; randomOrderList = new List&lt;int&gt;();
  
          for (int i = 0; i &lt; maximum; i++)
          {
              intsToAdd.Add(i);
          }
          while (intsToAdd.Count &gt; 0)
          {
              //Returns a random int between 0 and n-1, inclusive.
              int randomInt = random.Next(intsToAdd.Count);
              randomOrderList.Add(intsToAdd[randomInt]);
              intsToAdd.RemoveAt(randomInt);
          }
  
          return randomOrderList;
      }
  </code></pre>