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



If that you must generate a random string that appears one thing like this: VUNBXJ-230411, then you need to use 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 that you must alter the size of string A and B, then you possibly can change the worth within the vary above from one thing apart from 6.