Created
February 17, 2016 17:22
-
-
Save rjzak/2fcd0cf2d36db2691feb to your computer and use it in GitHub Desktop.
For when you need some random keys as a string, with optional starting value and optional length
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
import random | |
def randomKey(start=None, bytes=16): | |
if start is None: | |
part = "%02x" % random.randint(0,255) | |
return randomKey(part, bytes) | |
elif len(start.split(" ")) == bytes: | |
return start | |
else: | |
part = "%s %02x" % (start, random.randint(0,255)) | |
return randomKey(part, bytes) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment