Random Unique ID Generator

  • Share this:

Code introduction


This function generates a unique identifier of a specified length using the random and string built-in libraries, commonly used for generating user IDs, order numbers, etc.


Technology Stack : random, string

Code Type : Generate unique identifier

Code Difficulty : Intermediate


                
                    
def unique_id(length=8):
    import random
    import string
    return ''.join(random.choices(string.ascii_letters + string.digits, k=length))                
              
Tags: