Basic random functions
- Posted by kajyr on November 28th, 2009
- Comment now »
Here are some really basic (but useful) functions that returns random stuff…
The really basic one, is built in the Flash api and it returns a Number between 0 and 1:
A number in a range
Sometime is more useful to have a random number in a different range, let’s say between 15 and 45, instead of 0 and 1.
Random int
and what if we don’t need decimals? Round’em!
Random boolean
True or false? Flip a coin.
Random sign
-1 or 1; Useful when you have to random select random rotation verse, for example, -1*45 or 1*45, rotates counterclockwise or clockwise.
Random color
Really useful when drawing debug shapes on screen..
Random point
Inside an area. I like to use the flash.geom.Rectangle struct to describe an area, more than using 4 parameters (Flash api are quite inconsistent about this choice)
Do you want to leave a comment?