Shuffle a Vector in ActionScript 3
During a Project i needed a method which shuffles a Vector. Since i could not find an implemented shuffle() function i remembered how PHP works with sort-functions and came up with this really simple comparison function:
package de.patricktresp.util { /** * @author patricktresp */ public class VectorUtil { public static function shuffleVector( a : Object, b : Object ) : int { // HIDE FDT WARNINGS a; b; return Math.floor( Math.random() * 3 - 1 ); } } }
So whenever needed i just go:
vector.sort( VectorUtil.shuffleVector );
This works fine for now, but i am very sure there is some more efficient and faster methods.
Suggestions are appreciated.