This works for me:

for(i=0; i<5; i++){
        seq[i]=99;
        do{
                mflg=0;
                x=Math.floor(Math.random()*16);
                        for(j=0; j<=i; j++){
                                if(x==seq[j]) mflg=1;
                        }
        } while(mflg==1);
        seq[i]=x;
}

Odie

On Nov 30, 2006, at 5:49 PM, Corban Baxter wrote:

Quick question. Whats the fastest way to get 5 random numbers out of a list
of X number of numbers without having any duplicates?

Kinda like the script below excpet it graps duplicates...

var loopNum:Number = 16;

function getRandomNums(){
   for(i=0; i<5; i++){

       lastNum = newNum;

       while(newNum == lastNum){
           newNum = random(loopNum);
       }

       questionOrder[i] = newNum;
   }
   trace(questionOrder); // 0,1,3,2,3 "how do I get no duplicates?"

}

--
Corban Baxter
http://www.projectx4.com
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to