ActionScript 3 Random Value Generation Create a random color

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

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).



Got any ActionScript 3 Question?