title: Fisher–Yates Shuffle table rows
body: <p>I intend to use the Fisher-Yates shuffle to shuffle existing rows of a given table such as:</p>
  
  <pre><code>&lt;table&gt;
      &lt;tbody id="parent"&gt;
          &lt;tr id="node1"&gt;
              &lt;td&gt;1&lt;/td&gt;
              &lt;td&gt;A&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr id="node2"&gt;
              &lt;td&gt;2&lt;/td&gt;
              &lt;td&gt;B&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr id="node3"&gt;
              &lt;td&gt;3&lt;/td&gt;
              &lt;td&gt;C&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr id="node4"&gt;
              &lt;td&gt;4&lt;/td&gt;
              &lt;td&gt;D&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr id="node5"&gt;
              &lt;td&gt;5&lt;/td&gt;
              &lt;td&gt;E&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr id="node6"&gt;
              &lt;td&gt;6&lt;/td&gt;
              &lt;td&gt;F&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>With some help of JQuery, I have the following:</p>
  
  <pre><code>var parent = $("#parent");
  
  function shuffleRows(parent) {
      var rows = parent.children();
      for (var i = rows.length - 1; i &gt; 0; i--) {
          var j = Math.floor(Math.random() * (i + 1));
          var temp = rows[i];
          rows.eq(i - 1).after(rows[j]);
          rows.eq(j - 1).after(temp);
      }
  }
  
  shuffleRows(parent);
  </code></pre>
  
  <p>A working example is here: <a href="http://jsfiddle.net/98q9S/" rel="nofollow">http://jsfiddle.net/98q9S/</a></p>
  
  <p>However, as I test the above, I can't help but notice that row <code>A</code> gets the top spot far more often than other rows, and sometimes two consecutive shuffle produces the exact sequence of rows.</p>
  
  <p>I wonder if there is anything wrong in my implementation, or it is just that my sample size is too small.</p>