random Array generator class

snipped by interactiveSection

in Actionscript 3.0 syntax. from http://interactivesection.wordpress.com/. Use this class to generate and return a new array with x number of elements in a random order, or return a new array which has the same set of elements as an existing array at a randomized order.

Examples: [+] input: RandomArray.generateRdmArray(6); possible output: returning generated array: 1,5,4,2,3,0 [+] input: RandomArray.generateRdmArray(6, ["LA", new MovieClip(), "bb", 90000, new Object(), [0,1,2] ]); possible output: returning generated array: LA, 0,1,2, bb, [object Object], 90000, [object MovieClip] (Note: here 0,1,2 together make one element (an array with 3 elements) in the result array, which has six elements in total) [+] input: RandomArray.generateRdmArray(3, ["a","b","c","d","e"]); possible output: returning generated array: a,c,d (Note: the original array has more elements than the result array, so just pick 3 random elements from the original array to make the result array )

package com.interactiveSection.utils{
	public class RandomArray{
		public function RandomArray():void{};
		public static function generateRdmArray(numElements:int, origArray:Array=null):Array{
			if (origArray==null || numElements>origArray.length) {
				origArray = (origArray==null)? new Array():origArray;
				for (var i:int = origArray.length; numElements>i; i++){
					origArray.push(i);
				}
			}
			//
			var tempArray:Array = new Array();
			tempArray = origArray.slice();
			var resultArray:Array = new Array();
			while (tempArray.length>0 && numElements>resultArray.length){
				var rdm:int = Math.floor(Math.random()*tempArray.length);
				resultArray.push(tempArray[rdm]);
				tempArray.splice(rdm,1);
			}
			trace("returning generated array: "+resultArray);
			return resultArray;
		}
	}
}