Jan-26-2021, 10:28 AM
Similar to bowlofred solution:
import random def get_random_hex_str(hex_length): if hex_length % 2 != 0: raise ValueError("hex_length must be even") maximum = 2 ** (4 * hex_length) - 1 value = random.randint(0, maximum) return f"{value:0{hex_length}x}"A cryptographic safe solution is the use of
os.urandom
import os from binascii import hexlify def get_random_hex_str(hex_length): if hex_length % 2 != 0: raise ValueError("hex_length must be even") return hexlify(os.urandom(hex_length // 2)).decode()
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
All humans together. We don't need politicians!