title: How do I shuffle a Javascript Array ensuring each Index is in a new position in the new Array?
body: <p>I have an Array of Objects, like so.</p>
  
  <pre><code>var usersGoing = [
      { user: 0 },
      { user: 1 },
      { user: 2 },
      { user: 3 },
      { user: 4 }
  ];
  </code></pre>
  
  <p>I need to shuffle this Array so that no Object remains in the same index as when it was instantiated, like so:</p>
  
  <pre><code>[
      { user: 3 },
      { user: 2 },
      { user: 4 },
      { user: 0 },
      { user: 1 }
  ]
  </code></pre>
  
  <p>It is IMPERATIVE that the resulting array be sorted in this manner, as each of these user Objects will be assigned to a different user Object.</p>
  
  <p>I have tried a few different sorting algorithms, including Fisher-Yates, and I've tried using Underscore.js' _.shuffle(), and this variant from Kirupa <a href="http://www.kirupa.com/html5/shuffling_array_js.htm" rel="nofollow noreferrer">Shuffling an Array in JavaScript</a>:</p>
  
  <pre><code>function shuffleFY(input) {
      for (var i = input.length-1; i &gt;=0; i--) {
          var randomIndex = Math.floor(Math.random()*(i+1)); 
          var itemAtIndex = input[randomIndex]; 
  
          input[randomIndex] = input[i]; 
          input[i] = itemAtIndex;
      }
      return input;
  }
  </code></pre>
  
  <p>Nothing I've tried is working.  Help?</p>
  
  <p>UPDATED: I've marked an answer as correct below, as the key points of the Sattolo Cycle were followed correctly.  Also, this is NOT a duplicate of <a href="https://stackoverflow.com/questions/15003825/shuffles-random-numbers-with-no-repetition-in-javascript-php">Shuffles Random Numbers with no repetition in Javascript/PHP</a> as this question has the additional requirement of the resulting array not only not containing duplicates, but also cannot contain items in their same initial index position.</p>