Skip to content

Instantly share code, notes, and snippets.

@kgriffs
Created May 12, 2021 00:01
Show Gist options
  • Save kgriffs/cc977ae29505213c8a8a4ef742494d6e to your computer and use it in GitHub Desktop.
Save kgriffs/cc977ae29505213c8a8a4ef742494d6e to your computer and use it in GitHub Desktop.
Python: Generate a random string of random length from a finite character set
def randstr(max_count=32, charset=(string.ascii_letters + '-')):
return ''.join(
random.choice(charset)
for _ in range(random.randint(1, max_count))
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment