vendredi 10 janvier 2020

Python Random String/Text/Code generator with fixed length and some characters

Hello dear StackOverflow family! It might be a little bit late, but still Happy New Coding Year to all!

So, a few years ago I have found an exploit in the giftcard system at McDonalds. The basic point is by combining about 15-20 cards, and their codes, I got a point that 3rd and the 7th characters are the same while the others are completely random. I might have found the same thing in the new Coke festival that is taken in my area (Turkey). I just wanted to ask, how can I develop a code with random module that it will randomly create codes by going over a specific algorithm, for example let's go with the same 3rd and 7th characters again. By keeping them, randomly generate 8 numbered/lettered codes. Also I think using the while True would be better to generate like infinite amount of them. I will finally add them into a list. However, I need your help in the middle part.

import random
import string

def randomStringDigits(stringLength=6):
    lettersAndDigits = string.ascii_letters + string.digits
    return ''.join(random.choice(lettersAndDigits) for i in range(stringLength))

print ("Generating a Random String including letters and digits")
while True:
    print ("First Random String is  ", randomStringDigits(8))



Aucun commentaire:

Enregistrer un commentaire