Advertisement
rg443

javascript shuffle

Mar 16th, 2013
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // http://jsperf.com/optimized-fisher-yates
  2. function shuffle(array) {
  3.   for (var tmp, cur, top=array.length; top--;){
  4.     cur = (Math.random() * (top + 1)) << 0;
  5.     tmp = array[cur]; array[cur] = array[top]; array[top] = tmp;
  6.   }
  7.   return array;
  8. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement