Posted by Philip Bulley | Filed under Actionscript 3
UPDATE: Please see comments below for a shuffle technique using the efficient Fisher-Yates algorithm.
Whilst working on an AS3 project, I figured I needed to shuffle the order of a Vector. A quick Google search looking for a code snippet that will shuffle the order of an Array will produce many results (although I’d most likely use the nicely packaged CasaLib’s ArrayUtil.randomize()). But the same is not true (at least as of writing) for shuffling the order of a Vector.
So this post is for anyone stumbling on in from Google, requiring a quick “I can’t be bothered to think about it” solution:
Just to note, Array.sort() has never won any awards for code execution speed, so it’s likely that Vector.sort() won’t either.