Saturday, May 27, 2023
HomeSoftware EngineeringThe best way to Generate Random Strings with Sprint in-between in Python

The best way to Generate Random Strings with Sprint in-between in Python


If you have to generate a random string that appears one thing like this: VUNBXJ-230411, then you should utilize the next random generator:

import random, string

def generate_random_string_with_dash():
    rand = "{0}-{1}".format(''.be part of(random.alternative(string.ascii_uppercase) for x in vary(6)),
                            ''.be part of(random.alternative(string.digits) for x in vary(6)))
    return rand

You merely name the above as follows:

print( generate_random_string_with_dash() )
# JJXFNS-420809

If you have to alter the size of string A and B, then you’ll be able to change the worth within the vary above from one thing apart from 6.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments