get_random

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

 

posted @ 2024-04-23 15:54  AngDH  阅读(4)  评论(0编辑  收藏  举报