Monday, May 22, 2023
HomeSoftware EngineeringTips on how to Generate Random Strings with Sprint in-between in Python

Tips on how to Generate Random Strings with Sprint in-between in Python


If it’s essential to generate a random string that appears one thing like this: VUNBXJ-230411, then you should use the next random generator:

import random, string

def generate_random_string_with_dash():
    rand = "{0}-{1}".format(''.be part of(random.selection(string.ascii_uppercase) for x in vary(6)),
                            ''.be part of(random.selection(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 it’s essential to modify the size of string A and B, then you may 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