lundi 18 juillet 2022

Generating Random Strings With Repeats and Blanks - Python

Hello I have been successful in generating random strings, but I am now looking to make sure there are a couple of repeating strings and a couple of blank strings. My current code looks like

import random
import string
import numpy as np

def randomGenerator(length):
#   for i in range(0,16):
    randomString = ''.join(random.choice(string.ascii_uppercase + string.digits) for i in range(length))
    return randomString


for i in range(0,16):
    listOne = [randomGenerator(8)]
    mat = np.array([listOne])
    print(mat)

The Output I get:

[['3DYKRYHV']]
[['D78NVRZ1']]
[['4BLPD8IB']]
[['D94C73DQ']]
[['1ZDIC5AJ']]
[['XEEEV4JP']]
[['PM9WQ0WM']]
[['4CK2O7F5']]
[['D4GEPXI8']]
[['MVWNOMY5']]
[['TOSS2USW']]
[['1DCQ5JV0']]
[['UR8UUPL7']]
[['17Y7ZIWF']]
[['EABGQ1X3']]
[['KZVBAZRM']]

The Output I am looking For:

[['3DYKRYHV']]
[['D94C73DQ']]
[['        ']]
[['D94C73DQ']]
[['1ZDIC5AJ']]
[['        ']]
[['PM9WQ0WM']]
[['3DYKRYHV']]
[['D4GEPXI8']]
[['3DYKRYHV']]
[['UR8UUPL7']]
[['1DCQ5JV0']]
[['UR8UUPL7']]
[['        ']]
[['EABGQ1X3']]
[['KZVBAZRM']]

for something close to that. I am need the some strings to repeat and some empty slots. Thank you for the help in advance




Aucun commentaire:

Enregistrer un commentaire