ActionScript 3 Random Value Generation Create a random color


Example

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 << 16 | g << 8 | b;

Here you can specify your own range for r, g and b (this example is from 0-255).