mardi 15 septembre 2015

python : get random value not exist in list

I have a the following code:

def random_generate(list)
    x = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
    x = list(x)
    random = choice(x)+choice(x)+choice(x)


and i want to pass a list like that : ["abc","acd","aza"]
like that:

random_generate(["abc", "acd", "aza"])

to the random function so it will never generate a random included at this list.
in other word it will never generate "abc" or "acd" or "aza" again.
i know i can make it to loop many times to generate random 3 chars and check if it is exist in the list, but i need something more efficient.




Aucun commentaire:

Enregistrer un commentaire