goldies
    Preparing search index...
    • Generates a random hexadecimal color code within a specified RGB range.

      Creates a random color where each RGB component is independently randomized between the corresponding components of the two colors. This is useful for generating colors within a specific color palette or theme.

      Parameters

      • minColor: string = '#000000'

        One bound of the range, as a 3- or 6-digit hex color. The leading # is optional. Defaults to #000000 (black).

      • maxColor: string = '#ffffff'

        The other bound, as a 3- or 6-digit hex color. The leading # is optional. Defaults to #ffffff (white). If a channel of minColor is the higher one, the bounds for that channel are swapped.

      Returns string

      A random 6-character hexadecimal color code with leading #, where each RGB component falls within the specified range.

      If either color isn't a 3- or 6-digit hex color.

      // Generate any color in the full spectrum
      generateRandomHexColorInRange('#000000', '#ffffff');
      // => '#7a3f2c' (or any random hex color)
      // Generate a shade of blue
      generateRandomHexColorInRange('#000066', '#0000ff');
      // => '#0000a3'
      // Generate warm colors (reds/oranges)
      generateRandomHexColorInRange('#800000', '#ff8800');
      // => '#c24510'
      // Generate muted colors, with every channel between 0x33 and 0xcc
      generateRandomHexColorInRange('#333333', '#cccccc');
      // => '#7a4f9c'
      // Using default values
      generateRandomHexColorInRange();
      // => '#4f8c2a' (same as full spectrum)