7 responses to “AS3 Vector shuffle or randomize”

  1. dawe

    Note: We use com.gskinner.utils.Rndm class because it generates random numbers based on a seed number: necessary if you have to reproduce a random output.
    If you don’t have or want to use this class, change line 11
    var s:Number = Rndm.integer(0, vec.length);
    var s:Number = Math.round(Rndm.random()*(inVector.length-1));

    again Rndm!!! And “inVector”

  2. Philip Bulley

    Hey, I came across the same Vector shuffle issue around the time you did too 🙂 Here’s was my solution:


    In think yours will be more efficient as I’m just hijacking the vector sort method.

    By the way, I tried casting a Vector.int to Vector.*, but the vector becomes null within the shuffle method. So did this actually work for you?

  3. Mike

    Great article!
    I noticed there is a slight typo in the last line of this post.
    should be

  4. Joe Billman

    Thanks for the great code snippet! I was looking for a good way to shuffle a Vector.

  5. dSilva

    Thanks for the code. Nice help.
    But seems like there’s still a typo at:

    var s:Number = Math.round(Math.random()*(vec.length));

    Where it should read:

    var s:Number = Math.round(Math.random()*(vec.length-1));
    var s:Number = Math.floor(Math.random()*(vec.length));

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.