Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //http://blog.codinghorror.com/the-danger-of-naivete/
- //Knuth-Fisher-Yates shuffle
- function shuffle(array:Array):Array
- {
- var m:int = array.length;
- var t:*;
- var i:int;
- while (m){ // While there remain elements to shuffle…
- i = Math.floor(Math.random() * m--); // Pick a remaining element…
- t = array[m]; // And swap it with the current element.
- array[m] = array[i];
- array[i] = t;
- }
- return array;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement