-
google has faild me on a simple question.
If I wanted the range of the random numbers for flash to be between 3 to 8, I would rewrite the below actionscript to..?
(random(3)+1)
-
I'd use: random(6)+3;
g'luck.
Last edited by gomar; 10-27-2005 at 08:11 AM.
Reason: typo
- g
-
The use of random() has been deprecated. You should use Math.random() instead.
Code:
var someNum:Number = Math.floor( Math.random() * 6 )+3;
trace( someNum );
Per the documentation on LiveDocs, Math.random() will return a number between [0 and 1), or as they write it, 0 <= n < 1. Which means you can potentially return a zero, but never a 1, and anything in-between. So in the previous code, the maximum value you can get will be 5.999999 and never six. Math.floor() will drop the decimal portion of it, returning a number between 0 and 5, add 3, you get between 3 and 8.
Of course, if you're looking for decimals as well, get rid of the Math.floor() function
Last edited by wombatLove; 10-27-2005 at 08:26 AM.
Reason: Spell check
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|