🎲 Random Color Generator

Generate random colors for design inspiration, placeholders or picking an accent — with HEX, RGB and HSL values for each one.

Where the numbers come from

Each swatch is three independent draws of 0-255, taken from crypto.getRandomValues rather than Math.random, with rejection sampling so no value is favoured:

maxUint = floor(0xFFFFFFFF / 256) × 256 = 4294967040
draw a 32-bit value; if it is >= maxUint, throw it away and draw again
otherwise return value % 256

Taking % 256 straight off a 32-bit number would make the lowest outcomes very slightly more likely; discarding the top 256 values leaves exactly 16,777,215 possible draws per outcome, so all 256 are equally probable. The cost is one wasted draw in about 16.8 million. Each colour is then shown as hex, rgb() and hsl(), with the HSL derived from the RGB the usual way - lightness as the midpoint of the largest and smallest channel.

What uniform RGB actually gives you

Nothing here checks contrast. A random mid-lightness colour has no reliable relationship to white or black text, and most of them will fail 4.5:1 against both. Test any colour you keep before putting words on it.

Frequently asked questions

How many possible hex colours are there?

16,777,216 - that is 256 values in each of three channels, or 256³. Every one of them is equally likely to come up here.

Are these colours truly random?

They come from the browser's cryptographic random number generator, which is seeded from system entropy, so they are not reproducible and there is no sequence to predict. That is a stronger guarantee than Math.random gives.

Why do random colours rarely look good together?

Because a pleasing palette shares something - a hue relationship, a common saturation, an even lightness ramp - and independent draws share nothing. Use random output to find one starting colour, then build the rest around it.