title: How to generate random values that don't keep giving me the same value in 'runs' of numbers?
body: <p>Hi I coded this OneAtRandom() extension method:</p>
  
  <pre><code>public static class GenericIListExtensions
     {
        public static T OneAtRandom&lt;T&gt;(this IList&lt;T&gt; list)
        {
           list.ThrowIfNull("list");
           if (list.Count == 0)
              throw new ArgumentException("OneAtRandom() cannot be called on 'list' with 0 elements");
  
           int randomIdx = new Random().Next(list.Count);
           return list[randomIdx];
        }
  }
  </code></pre>
  
  <p>Testing it using this unit test fails:</p>
  
  <pre><code>[Test]
          public void ShouldNotAlwaysReturnTheSameValueIfOneAtRandomCalledOnListOfLengthTwo()
          {
              int SomeStatisticallyUnlikelyNumberOf = 100;
              IList&lt;string&gt; list = new List&lt;string&gt;() { FirstString, SecondString };
              bool firstStringFound = false;
              bool secondStringFound = false;
  
              SomeStatisticallyUnlikelyNumberOf.Times(() =&gt;
              {
                  string theString = list.OneAtRandom();
                  if (theString == FirstString) firstStringFound = true;
                  if (theString == SecondString) secondStringFound = true;
              });
              Assert.That(firstStringFound &amp;&amp; secondStringFound);
          }
  </code></pre>
  
  <p>It seems that <code>int randomIdx = new Random().Next(list.Count);</code>is generating the same number 100 times in a row, I think possibly because the seed is based on the time?</p>
  
  <p>How can I get this to work properly?  </p>
  
  <p>Thanks :)</p>