DEV Community

Lakshyaraj Dash
Lakshyaraj Dash

Posted on

How to generate random strings using python ?

In this post, you will learn how to generate random strings in python.

import random
import string

def generate_random_strings():
    chars = string.ascii_lowercase+ string.ascii_uppercase+ string.digits
    size = 12
    randomString = ''.join(random.choice(chars) for __ in range(size))

if __name__ == "__main__":
   generate_random_strings()
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Image of Stellar post

Discover what it takes to launch a Web3 startup

Bringing your Web3 idea to life and launching a startup can be a difficult, complicated process. Check out the Stellar Dev Diaries to learn from a team that is makiung it happen, in real time!

Learn more

AWS Security LIVE!

Hosted by security experts, AWS Security LIVE! showcases AWS Partners tackling real-world security challenges. Join live and get your security questions answered.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❤️