Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def create_guid():
- microTime = microtime()
- a_dec, a_sec = microTime.split(' ')
- dec_hex = '%x' % float(a_dec) * 1000000
- sec_hex = '%x' % int(a_sec)
- dec_hex = ensure_length(dec_hex, 5)
- sec_hex = ensure_length(sec_hex, 6)
- guid = ''
- guid += dec_hex
- guid += create_guid_section(3)
- guid += '-'
- guid += create_guid_section(4)
- guid += '-'
- guid += create_guid_section(4)
- guid += '-'
- guid += create_guid_section(4)
- guid += '-'
- guid += sec_hex
- guid += create_guid_section(6)
- return guid
- def microtime(get_as_float = False) :
- if get_as_float:
- return time.time()
- else:
- return '%f %d' % math.modf(time.time())
- def ensure_length(string, length):
- strlen = len(string)
- if strlen < length:
- string = string.ljust(length, '0')
- else:
- string = string[:length]
- return string
- def create_guid_section(characters):
- return ''.join(['%x' % random.randint(0, 15) for el in range(characters)])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement