>>Quick question. Whats the fastest way to get 5 random numbers out of a
list
>>of X number of numbers without having any duplicates?
I like this:
function rndNumArray(max:Number, noZero:Boolean):Array{
var a:Array = new Array();
var n:Array = new Array(max+1);
var zeroVal:Number = 0;
if (noZero==true){zeroVal=1};
for(var i; a.length < max;) {
if(n[i=Math.floor(Math.random()*max)+noZero])
continue;
a.push(i); n[i] = 1;
}
if(!noZero){
var rndPlace:Number = rndNum(0,max);
a.push(a[rndPlace]);
a[rndPlace]= max
a.pop();
};
return a;
}
Jason Merrill
Bank of America
Learning & Organizational Effectiveness
_______________________________________________
[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