vendredi 30 novembre 2018

Avoiding duplicate values using random module

Below is a "Brute Force" word guessing...thing. I'ts to prove to my sibling how long it takes to find a password even knowing the number of characters using brute force. After letting this run for a couple hours with no success I think he gets the point. Now I want to put some logic behind it and for the life of me I can't figure it out. I've found things similar to what I want online but I don't know how to adapt it to my code.

import string
import random

def make_random():
   return''.join([random.choice(string.ascii_uppercase) for n in xrange(3)])

while True:
   random2=make_random()
   if random2 != "AAA":
      print(random2)
   if random2 == "AAA":
      print("AAA")
      print("Found")
      break

I think I need to have a variable to keep track of all the choices that have been guessed and compare that to the new string and set them so they can't equal but I honestly don't know.

Any help is good help.




Aucun commentaire:

Enregistrer un commentaire