import random
"""
Generate unique HEX colors using randomness in Python.
Notes:
- random.randint(0, 255) gives values in the full RGB range.
- A set ensures uniqueness.
- Produces #RRGGBB strings.
"""
# Convert an integer (0–255) to a two-digit HEX string.
def to_hex(value: int) -> str:
return f"{value:02x}"
# Generate N unique random HEX colors.
def generate_random_unique_hex_colors(count: int) -> list[str]:
seen = set()
colors = []
while len(colors) < count:
r = random.randint(0, 255)
g = random.randint(0, 255)
b = random.randint(0, 255)
hex_color = f"#{to_hex(r)}{to_hex(g)}{to_hex(b)}"
if hex_color not in seen:
seen.add(hex_color)
colors.append(hex_color)
return colors
if __name__ == "__main__":
n = 12
colors = generate_random_unique_hex_colors(n)
print("Generated HEX colors:")
for c in colors:
print(c)
"""
run:
Generated HEX colors:
#674669
#659eea
#08d027
#2a52eb
#77784e
#8947de
#a1f9a0
#4fef3f
#8eb473
#c27f51
#42e8db
#d5f7c6
"""