Skip to content

Instantly share code, notes, and snippets.

@ahsanzizan
Created January 11, 2024 01:53
Show Gist options
  • Save ahsanzizan/fd356051c910a55ed352d93368511466 to your computer and use it in GitHub Desktop.
Save ahsanzizan/fd356051c910a55ed352d93368511466 to your computer and use it in GitHub Desktop.
A handy random string generator
import random
import string
def generate_random_string(length):
# Define the characters to choose from
characters = string.ascii_letters + string.digits + string.punctuation
# Generate a random string of the specified length
random_string = ''.join(random.choice(characters) for _ in range(length))
return random_string
length = int(input("Length: "))
print(generate_random_string(length))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment