Monday, July 28, 2008

[AS3]Random numbers

Here is a quick AS3 random number explanation. In AS3, the Math.Random generates a random number between 0 and 1. So with that, we can get a random number between 0 and any number. Here is an example. Lets say we want a random number between 0 and 10. First we would need a dynamic textbox. Give it the instance name "displayRand". This would be our code:
displayRand.text = Math.floor(Math.random() * 10) + " ";

This will now generate a random number. You can change the number after Math.random to anything depending on the range that you want. Post or email me any questions.

No comments: