Skip to content

Instantly share code, notes, and snippets.

@rjzak
Created February 17, 2016 17:22
Show Gist options
  • Save rjzak/2fcd0cf2d36db2691feb to your computer and use it in GitHub Desktop.
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
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