they do the same thing, but no, they are not the same. try this:code:
tests=100;
iterations=1000;//per test, defines accuracy
for(t=1 ; t<=tests ; t++){
t1=getTimer();
for(i=1 ; i<=iterations ; i++){
random(n);
}
trace((getTimer()-t1)/iterations);
t2=getTimer();
for(i=1 ; i<=iterations ; i++){
Math.random()*n;
}
trace((getTimer()-t2)/iterations);
trace("");
}
doing it by Math.random is consistently slower(tho they are both cons. less than .05 millisecond on my PC), as to be expected. anything hard coded in Flash *should* be faster.
[EDIT] if you take out the *n for the Math.random() you find that Math.random() is *still* about .01 - .05 of a millisecond slower... so i guess always use random()? of course, we are talking about debatably completely inconsequential difference in speed here... .01 of a millisecond????![]()




Reply With Quote