Shuffle/Randomize Array/Vector in AS3

As3 Array/Vector classes don’t provide an implemented method to shuffle/randomize them. However, that’s not a hard task to do and there are quite a few methods to implement such an algorithm. One of the easiest methods is called Fisher-Yates shuffle. Probably it’s not the fastest way to shuffle an array, but it does not require extra memory. You need to traverse the array a single time.

Here is the code to shuffle an array:

And here if you want to shuffle a vector:

Leave a Reply

Your email address will not be published. Required fields are marked *