function factorial(n):Number {
if (n < 2) {
return 1;
}
return n*factorial(n-1);
}
trace(factorial(3)); //Outputs 6
Welcome to my actionscript snippet library!
Actionscript Snips is a small repository of actionscript code that aims to save developers and designers time when developing a website.
Showing posts with label Math. Show all posts
Showing posts with label Math. Show all posts
Factorial
Generate Random Number
function randomRange(max:Number, min:Number = 0):Number
{
return Math.round(Math.random() * (max - min)) + min;
}
trace(randomRange(5)); //Outputs number between 0 and 5
trace(randomRange(10,1)); //Outputs number between 1 and 10
