Thursday, August 30, 2007

Random Numbers

Generating random number is the same as it was in AS2, but I always forget how so here are a few ways:

Math.round(Math.random() * 1000); //Gets a whole number anywhere from 0 - 1000
Math.floor(Math.random() * 10); //From 0 - 9 (cuz floor always rounds down)
Math.ceil(Math.random() * 10); //from 1 - 10 (cuz ceil always rounds up)
Math.round(Math.random() * 15) + 5; //from 5 - 20
Math.round(Math.random() * 10) - 5; //from -5 - 5

1 comment:

Anonymous said...

You can download CodeDrive on http://www.codedrive.com
Intelligent IDE for ActionScript 3 based on Microsoft Visual Studio with refactorings, code completion, on-the-fly code analysis, debugger and coding productivity orientation.