🎲 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
- Mid-lightness dominates. Because L is the average of the brightest and darkest of three uniform draws, extremes are rare: only about 3% of colours land below 20% lightness and another 3% above 80%. You will wait a long time for a good pastel or a near-black.
- Saturation averages around 67%, and roughly one in five colours reaches 90% or more. Vivid is possible but not typical.
- There is no relationship between swatches. This generates colours, not palettes - for a coherent set, take one result you like and feed it to a harmony generator.
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.