title: Why does using Random in Sort causing [Unable to sort IComparer.Compare error]
body: <p>I tried shuffling a list of byte (List) using either code: </p>
  
  <pre><code>myList.Sort((a, b) =&gt; this._Rnd.Next(-1, 1));
  </code></pre>
  
  <p>or</p>
  
  <pre><code>myList.Sort(delegate(byte b1, byte b2)
  {
      return this._Rnd.Next(-1, 1);
  });
  </code></pre>
  
  <p>and they threw the following error:</p>
  
  <p>Unable to sort because the IComparer.Compare() method returns inconsistent results. Either a value does not compare equal to itself, or one value repeatedly compared to another value yields different results. x: '{0}', x's type: '{1}', IComparer: '{2}'.</p>
  
  <p>What is wrong with using a random rather than the compare function of byte?</p>
  
  <p>I tried using LINQ function instead and it works.</p>
  
  <pre><code>var myNewList = myList.OrderBy(s =&gt; Guid.NewGuid());
  var myNewList = myList.OrderBy(s =&gt; this._Rnd.NextDouble());
  </code></pre>
  
  <p>I did read that these methods are slower than Fisher–Yates shuffle giving O(n) runtime only. But was just wondering on using the Sort function and random.</p>