Sequence Randomiser

February 2nd, 2009

So I said I’d be back and here I am. I won’t bore you with specific excuses but I’ve honestly had a lot to do in the last few months.

Here’s another simple utility that came out of something old. It simply returns an array of consecutive integers, only in a random order, with no reptition. By default the smallest value is zero and the highest is the length of array requested – 1. However you can set the base value via an optional second argument.

A typical usage would be to trigger a number of animations in a random order.

Again, simple stuff but if it saves you 10 minutes then this post was worthwhile.

Files:
com.aderowbotham.utils.SequenceRandomiser

Usage:

import com.aderowbotham.utils.SequenceRandomiser;

//create a sequence of length 10
var mySequence:Array = SequenceRandomiser.createSequence(10);
trace(mySequence);    //e.g. 5,0,7,8,2,4,1,9,6,3

//create a sequence of length 10, from -5
mySequence = SequenceRandomiser.createSequence(10,-5);
trace(mySequence);    //e.g. -4,-5,0,-3,2,1,3,-2,4,-1

Leave a Reply