Skip to main content
RC

Random Color Generator

Generate truly random colours with channel locking and a 5-colour history — copy the hex code with one click.

Did you like the tool? Thanks!
Share:
or press Space

RGB:

HSL:

Channel locks

How to Use Random Color Generator

Click the Generate button to produce a random colour using cryptographically strong randomness. The colour is displayed as a large swatch, with its HEX, RGB, and HSL values shown underneath. Toggle any of the R, G, or B channel locks to freeze that channel — clicking Generate again randomises only the unlocked channels. The last 5 generated colours are saved as a clickable history row; clicking any history swatch restores that colour and reloads its values.

About Random Color Generator

Most "random colour" tools on the web call `Math.random()` to produce red, green, and blue channel values. This is fast and simple, but `Math.random()` is a pseudo-random number generator (PRNG) — its output is deterministic given the internal state, and while it is unpredictable enough for casual use, it is not suitable when genuine unpredictability matters (for example, generating a one-time colour token for a security-sensitive context, or running a lottery-style colour picker where fairness is auditable). This tool uses `crypto.getRandomValues()` instead, which sources entropy from the operating system's cryptographically secure random number generator. It fills a `Uint8Array` of length 3 with random bytes, giving each channel a uniformly random integer between 0 and 255 with no bias and no predictable pattern. **Channel locking** is the feature that sets this tool apart from most generators. Each of the three colour channels — Red, Green, and Blue — has a lock/unlock toggle button next to it. When a channel is unlocked (default), it gets a fresh random value every time you click Generate. When a channel is locked, its current value is preserved and only the other channels are randomised. This lets you explore deliberately constrained colour families: lock Red at 255 to explore only warm colours (reds, oranges, yellows); lock Red and Green while randomising Blue to walk through a single hue at varying intensities; or lock two channels to 0 and randomise the third to generate pure shades of a single primary colour. **History:** The last 5 generated colours are stored in a simple array. Each entry is a clickable swatch — clicking one restores that colour's values into the main display and sets the locked channels back to whatever their state was irrelevant (the locked switches are not tied to history entries; they are a separate, persistent UI state). The history is ephemeral — it lives only in the current page session and is lost on refresh, which keeps the tool lightweight and avoids any local-storage privacy concern.

Details & Tips

Randomness implementation: ``` function randomChannel() { const arr = new Uint8Array(1); crypto.getRandomValues(arr); return arr[0]; } ``` Each call fills a single byte from the OS entropy source (`/dev/urandom` on Linux, `CryptGenRandom` on Windows, the Secure Enclave on macOS/iOS). The distribution is uniform over 0-255 with no modulo bias — the raw byte value is used directly, not the result of a modulo operation on a larger random number, so every possible channel value is equally likely. **Channel locking implementation:** The Alpine.js state holds three booleans — `lockR`, `lockG`, `lockB` — and three integers — `r`, `g`, `b`. The generate function first saves the current channel values; then calls `randomChannel()` for each channel whose lock flag is false; then recomputes hex, rgb string, and hsl from the new triple. The lock toggles are `<button>` elements with a visual state (locked = a closed padlock icon, unlocked = an open padlock icon, using simple text or SVG). **History implementation:** An array `history` holds up to 5 objects, each with `hex`, `r`, `g`, `b`. On generate, the new colour is unshifted onto the front of the array; if the array exceeds 5, the oldest entry is popped. Clicking a history swatch sets the current `r`, `g`, `b`, and `hex` to the clicked entry's values, recomputes the display, but does not change the lock states (so clicking Generate after restoring a history colour will respect the locks as they currently are, not as they were when that colour was first generated). **Display formats:** The hex code is shown as a large, copyable string (e.g. `#C73E1D`). The RGB string uses the `rgb(r, g, b)` CSS functional notation. The HSL string uses `hsl(h, s%, l%)` with hue as a rounded integer and saturation/lightness as rounded percentage integers. A Copy button next to the hex value copies the 7-character hex string (with hash) to the clipboard. The colour swatch is a large square (at least 120×120px) with rounded corners, displaying the generated colour as its background. **Accessibility:** The hex code is displayed as high-contrast text superimposed on the colour swatch itself, with the text colour flipped to white or black based on the luminance of the generated colour, ensuring the hex value is always readable regardless of the colour it sits on.

Frequently Asked Questions

How does the random colour generator work?
It uses `crypto.getRandomValues()` — the browser's cryptographically secure random number generator — to fill each colour channel with a uniformly random byte (0-255). This is stronger than `Math.random()`, which is a pseudo-random generator.
What is channel locking?
Each of the three colour channels — Red, Green, and Blue — has a lock button. When a channel is locked, its value stays the same when you click Generate; only the unlocked channels get new random values.
Why would I lock a channel?
Locking lets you explore constrained colour families — for example, lock Red at 255 to generate only warm colours, or lock two channels to 0 to get pure shades of the third primary colour.
How does the colour history work?
The last 5 generated colours are saved as swatches. Click any swatch to restore that colour to the main display. The history is reset when you refresh the page.
Is the randomness truly unpredictable?
Yes — `crypto.getRandomValues()` draws entropy from the operating system's secure random source, which collects environmental noise (hardware interrupts, disk timings, etc.). The output is suitable for cryptographic use, not just casual randomness.
Why not use Math.random()?
`Math.random()` is a PRNG — fast and adequate for games and casual use, but its sequence is deterministic given the internal seed. `crypto.getRandomValues()` provides genuine hardware-backed entropy and is the standard for security-sensitive randomness.
How do I copy the generated colour?
Click the Copy button next to the hex code. The 7-character value (including the #) is copied to your clipboard.
Can I see the colour in HSL format?
Yes — the generated colour is displayed in HEX, RGB, and HSL simultaneously, so you can read whichever format you need.
What is the range of each channel's random value?
0 to 255, inclusive, with uniform probability — every possible 8-bit channel value is equally likely. This means every possible colour in the 24-bit RGB space (over 16.7 million colours) can be generated.
Is the colour swatch text readable on any generated colour?
Yes — the hex code displayed on the swatch automatically switches to white or black text based on the generated colour's luminance, ensuring sufficient contrast for readability.
Is my data sent to a server?
No — randomness generation and all colour calculations happen entirely in your browser. Nothing is transmitted anywhere.
Can I save more than 5 colours in history?
The on-screen history is limited to the 5 most recent colours to keep the interface clean. You can copy and paste colours into a separate document if you need a longer record.

Part of These Collections

Also Available As

random color generator, random colour picker, random hex color, color generator, random rgb, crypto random color, lock channel color, color randomizer

Found a Problem?

Let us know if something with Random Color Generator isn't working as expected.

Thanks — we'll take a look.