Random Hex Color Generator

  • Share this:

Code introduction


This function generates a random color in hexadecimal format. It uses the standard libraries random and string.


Technology Stack : Python, random, string

Code Type : Python Function

Code Difficulty : Beginner


                
                    
def random_color_hex():
    import random
    import string
    
    def get_random_color():
        return '#' + ''.join(random.choices(string.hexdigits, k=6))
    
    return get_random_color()