Last active
August 18, 2023 21:07
-
-
Save seanpianka/11ba7d6b2f2683ca8768c72856c07565 to your computer and use it in GitHub Desktop.
Generate a random hex string/key in Python 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def generate_hex_string(length: int): | |
""" Generate a randomized hex string. | |
Parameters | |
---------- | |
length : int | |
Desired character length of the returned token. | |
Returns | |
------- | |
str | |
Randomly generated token with length of `length`. | |
""" | |
return "%030x" % random.randrange(16 ** length) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for catching that 😄