jeudi 23 juillet 2020

Replace substring randomly Python

I'm trying to replace every occurence of an int literal with a random generated value. But for each "int" it gets generates towards the same value for each location. How can I change each location randomly?

if '"int"' in addstr3:

randint = random.randint(0, 100)

addstr4 = addstr3.replace('"int"', str(randint))

else:

addstr4 = addstr3




Aucun commentaire:

Enregistrer un commentaire