Tutorial by Examples

Math.random(); produces an evenly distributed random number between 0 (inclusive) and 1 (exclusive) Example output: 0.22282187035307288 0.3948539895936847 0.9987191134132445
function randomMinMax(min:Number, max:Number):Number { return (min + (Math.random() * Math.abs(max - min))); } This function is called by passing a range of minimum and maximum values. Example: randomMinMax(1, 10); Example outputs: 1.661770915146917 2.5521070677787066 9.4362709657...
function randomAngle():Number { return (Math.random() * 360); } Example outputs: 31.554428357630968 230.4078639484942 312.7964010089636
Assuming we have an array myArray: var value:* = myArray[int(Math.random() * myArray.length)]; Note we use int to cast the result of Math.random() to an int because values like 2.4539543 would not be a valid array index.
First define the circle radius and its center: var radius:Number = 100; var center:Point = new Point(35, 70); Then generate a random angle in radians from the center: var angle:Number = Math.random() * Math.PI * 2; Then generate an effective radius of the returned point, so it'll be inside ...
function randomAngleRadians():Number { return Math.random() * Math.PI * 2; } Example outputs: 5.490068569213088 3.1984284719180205 4.581117863808207
If you need to roll for a true or false in an "x% chance" situation, use: function roll(chance:Number):Boolean { return Math.random() >= chance; } Used like: var success:Boolean = roll(0.5); // True 50% of the time. var again:Boolean = roll(0.25); // True 25% of the time. ...
To get any random color: function randomColor():uint { return Math.random() * 0xFFFFFF; } If you need more control over the red, green and blue channels: var r:uint = Math.random() * 0xFF; var g:uint = Math.random() * 0xFF; var b:uint = Math.random() * 0xFF; var color:uint = r <&...
var alphabet:Vector.<String> = new <String>[ "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", &q...
var alphabet:Array = [ "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S...

Page 1 of 1