lundi 23 janvier 2017

generate unique id in python

I want to make IDs for my application, is there any fast way to make sure that there will not be 2 same IDs? (The ID's length have to be 8 or 10 chars)

This is my code:

    def get_unique_id(self):
       chars = "abcdefghijklmnopqrstuvwxyzABSDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
       id = ""
       for _ in range(10):
           id+=chars[random.randrange(len(chars))]
       return id




Aucun commentaire:

Enregistrer un commentaire