Toolbox-XToolbox-X

Generate Random Color

Generates unique random colors in HEX, RGB, or HSL format, ensuring visual distinctness.

generateRandomColor

The generateRandomColor function generates a random, perceptually unique color in one of three formats: Hex6, RGB, or HSL. It tracks previously generated values to prevent duplicates and keep colors visually distinct.

Function Signature

function generateRandomColor<C extends $ColorType = "hex">(
  options?: RandomColorOptions<C>
): RandomColor<C>

Parameters

  • options (RandomColorOptions, optional): Configuration options:
    • colorType ('hex' | 'rgb' | 'hsl'): The format of the returned color. Defaults to 'hex'.
    • maxColors (number): The maximum number of recent colors tracked in memory. Defaults to 16.

Return Value

  • Hex6 | RGB | HSL: The randomly generated color string.

Example Usage

playground.ts

Aliases

The following aliases can be used for the generateRandomColor function:

  • getRandomColor

generateRandomHSLColor

Generates a unique random color specifically in HSL format.

Function Signature

function generateRandomHSLColor(maxColors?: number): HSL

Parameters

  • maxColors (number, optional): Maximum number of recent colors to track. Defaults to 16.

Example Usage

playground.ts

Aliases

The following aliases can be used for the generateRandomHSLColor function:

  • generateRandomHSL
  • getRandomHSL

Last updated: Mon, Jun 15, 2026 11:04:47AM (UTC)

On this page