How to generate a random HEX RGB color code in Python

1 Answer

0 votes
import random

def generate_random_hex_color():
    hex_chars = "0123456789ABCDEF"
    hex_code = ''.join(random.choice(hex_chars) for _ in range(6))
    return hex_code
    

print(f"Random HEX Color: #{generate_random_hex_color()}")



'''
run:

Random HEX Color: #68D381

'''

 



answered Oct 9 by avibootz
...