def get_random(): import os import random import string import binascii def to_hex(val): return format(val, '02x') def random_string(length): letters = string.ascii_letters + string.digits return ''.join(random.choice(letters) for _ in range(length)) # Create a byte array of length 17 with random values r = os.urandom(17) # Convert the byte array to a hex string hex_string = ''.join(to_hex(x) for x in r) # Generate a random string of length 7 rand_string = random_string(7) # Combine the hex string and the random string result = hex_string + rand_string print(result) return result
标签:letters,string,get,random,hex,length,import From: https://www.cnblogs.com/angdh/p/18153045