Quick "Shuffle" algorithm in JavaScript
I came up with a quick "shuffling" algorithm for JavaScript for a project I'm working on, and I'm just saving it here for future reference in case I need it again. Feel free to copy it if you need one too.
shuffle = function( list ) { var result = []; while( list.length > 0 ) { var i = Math.floor( list.length * Math.random() ); result.push( list.splice( i, 1 ) ); }; return result; }
Comments
Comments powered by Disqus