Random OKLab Color Generator

Generate an OKLab tuple with lightness in [0, 1) and a/b axes in [-0.4, 0.4) using injected randomness; the tuple is not clipped to a device gamut.

Description

Sample OKLab fractional lightness and two opponent-axis coordinates independently within fixed ranges.

OKLab represents color using lightness L and two opponent axes a and b. It was designed for perceptual color calculations; these coordinates differ from ordinary RGB channel bytes.1

This generator returns lightness on a 0–1 scale and a and b from −0.4 toward 0.4. Its sampling box includes coordinates that do not correspond to displayable sRGB colors.

CSS defines oklab() and oklch() representations for these spaces.2

When to use Random OKLab Color Generator

Use it for color-coordinate fixtures or exploratory color studies where values outside sRGB gamut are acceptable.

How to use Random OKLab Color Generator and understand its results

  1. Run with no input fields, or supply {} programmatically.
  2. Read lightness as a fraction and preserve the signed a and b coordinates.
  3. For the example, CSS oklab(0.25 -0.2 -0.2) preserves the output scale. Convert and check gamut separately before selecting a display color.
lightness = r1; a = −0.4 + 0.8 × r2; b = −0.4 + 0.8 × r3

Three finite random draws in [0, 1) independently set the coordinates.

The implementation returns these sampled numbers without RGB conversion, gamut mapping, clipping, alpha, or a formatted CSS string. Uniform coordinate sampling is not a uniform sample over visible or printable colors.

json
{
  "input": {},
  "randomDraw": 0.25,
  "output": {
    "lightness": 0.25,
    "a": -0.2,
    "b": -0.2
  }
}

Draw zero permits lightness zero and a = b = −0.4. The formulas approach but do not intentionally include lightness one or positive a and b endpoints 0.4.

Floating-point rounding applies near endpoints. An invalid draw in any coordinate fails rather than being clamped or replaced.

Limitations and assumptions

The default source is Math.random; no seed input or cryptographic entropy guarantee is provided. Repeated runs may select the same result, and the distribution depends on the random source.

The generator does not ensure sRGB or print gamut, contrast, color-vision accessibility, palette harmony, or an equal perceptual distribution.

The lightness field differs from the percentage scale used by this repository’s OKLCH generator. The two opponent coordinates require a polar conversion to obtain chroma and hue.

Alternative or Complementary methods

Use the related coordinate generator when its representation is intended. RGB generation provides directly bounded byte channels; conversion and gamut decisions remain separate.

References

  1. A perceptual color space for image processing — Björn Ottosson

  2. CSS Color Module Level 4: HSL and sRGB color representations — World Wide Web Consortium

Similar or alternative tools

Don't forget to set a bookmark for tool.io!
Privacy | Imprint | Cookies