|
-
Senior Member
Try below, Math.random gets number between 0 and 1, so if you use it like Math.random()*3, it will return 0,1,2. In the first example, it gets numbers 0-1580, then we subtract 30 to make the minimum value -30 and highest value 1580. I think that explanation is correct. I rarely use Math.random with such large numbers in my applications, so my experience is limited in that respect.
var randomNum:int = Math.random()*(1581+30)-30; // Integer, whole numbers, no decimals
var randomNum:Number = Math.random()*(2251+1045)-1045; // Number with trailing decimals
Use either int or Number, depending on what you want, i would use int for whole numbers.
Tags for this Thread
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
|