Basically in python there are some ways to get a random number with fixed digits like by using random
module
But here i am using python's uuid module to generate a random string like below
id = uuid.uuid4()
print id
UUID('decbb83f-9c35-4c37-a3d9-69e89bd8dd73')
But i want only 8 digit number from the above random UUID object
We can do something like
print str(id).split('-')[0]
which was not a UUID object but a string here
I am going to use this 8 digit random UUID(object) number in django UUID field like below
uuid = models.UUIDField(unique=True, default=uuid.uuid4, editable=False)
So how to get only 8 digit alphanumeric random UUID object ?
Aucun commentaire:
Enregistrer un commentaire