I have a list of ids and I want to display a fake id for each id in my list using Python.
I used the uuid1() but when there is a duplicated id in my list the program stop and don't generate the same random id for same input id.
print uuid.uuid1(data['user']['id']).int>>64
You could just hash your id :
import hashlib
id = 12
hashlib.sha256(str(id).encode()).hexdigest() # with python2.x you don't need to encode()
# => '6b51d431df5d7f141cbececcf79edf3dd861c3b4069f0b11661a3eefacbba918'
You'll have to store the correspondance somewhere though, because there is no way to retrieve the id from a hash.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments