dimanche 27 août 2017

Removing trailing dash from a randomly generated key

So using the code i have when generating a number/letter string it generates an extra dash on the end and i want it to only consist of 16 digits numbers and letters (without the extra dash)

import string, random

def generateCode():
    code = ''
    for i in xrange(16):
        number = random.choice(string.ascii_letters + string.digits)
        code += str(number)
        if (i - 3) % 4 == 0 and i - 4:
            code += '-'

    file = open('AlphaKeys.txt', 'w')
    file.write(code + '\n')
    file.close()
    return code

generateCode()

And an example of the output: qIss-wXbS-PZo7-audg-




Aucun commentaire:

Enregistrer un commentaire