Hyphenate a random string to an exact format
- by chrissygormley
Hello,
I am creating a random ID using the below code:
from random import *
import string
# The characters to make up the random password
chars = string.ascii_letters + string.digits
def random_password():
return "".join(choice(chars) for x in range(32))
This will output something like:
60ff612332b741508bc4432e34ec1d3e
I would like the format to be in this format:
60ff6123-32b7-4150-8bc4-432e34ec1d3e
I was looking at the .split() method but can't see how to do this with a random id, also the hyphen's must be at these places so splitting them by a certain amount of digits is out. I'm asking is there a way to split these random id's by 8 number's then 4 etc.
Thanks