5/29/2011 11:18:44 PM
Title:
randomization
I have 10 number of sets of question, I want to randomize these question that ever new opening the new sets will open
I paste this code on my file
////////////////////////////////////////////////////////////////////////
function randRange(min:Number, max:Number):Number {
var randomNum:Number = Math.round(Math.random()*(max-min))+min;
return randomNum;
}
var randomi = new Array();
for (var i = 0; i<=7; i++) {
_root.randomi.push(_root.randRange(0, 0));
}
///////////////////////////////
every time when i open my file it shows the same sets of question.
I want to randomise the sets.
please help me
6/2/2011 9:30:33 AM
you can use the following function to return the array of random array . Call it like this
shuffleArray(0,7)
public function shuffleArray(startIndex:int = 0, endIndex:int = 0):Array{
var randomArray:Array =new Array()
if(endIndex == 0) endIndex = this.length-1;
for (var i:int = endIndex; i>startIndex; i--) {
var randomNumber:int = Math.floor(Math.random()*endIndex)+startIndex;
var tmp:* = randomArray[i];
randomArray[i] = randomArray[randomNumber];
randomArray[randomNumber] = tmp;
}
return randomArray;
}