header
ask question
Click here to ask Question Now Its free No registration required. Flash, Flex, Flash Media Server, ActionScript,Adobe Air. Most questions receive a response in an hour.
anu
Points:0
Posts:0

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



1
Grey_crey
Points: 0
Posts:0
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;
}



Post your Reply
Name  

Email

Type your Reply or Answer

Are you human? What is 8+8 



Members Login

Email  
Password
Forgot Password





This website focus on: Flash | Flex | FMS | RED5 | WOWZA | Flash Media Server | Adobe AIR | ActionScript,Flash Solutions | Flash Question | Flash Answers | Flash Developers | Flash Problem, Flash Help, Flash bugs, Flash workaround | Flash Blog | Flex Question Answers | Flash Forum | Flex Development | Actionscript development | Flash development | Adobe AIR development
Copyright © 2008 AskMeFlash.com. All rights reserved. Privacy Policy | Terms & Conditions