diff --git a/S2/TP4/tp4.py b/S2/TP4/tp4.py index 4004711..588c350 100644 --- a/S2/TP4/tp4.py +++ b/S2/TP4/tp4.py @@ -118,12 +118,24 @@ squestion('b') # Effectuer de nombreuses recherches dans LEXIQUE # algorithmes utilisés # Définition des éléments choisis pour la recherche +from random import randint, SystemRandom +from string import ascii_lowercase, ascii_uppercase, digits + +def motAleatoire(taille): + return ''.join(SystemRandom().choice(ascii_lowercase + ascii_uppercase + digits) \ + for i in range(taille)) def creerListeRecherche(l, dans, hors): elements = list() taille = len(LEXIQUE) for n in range(dans): elements.append(LEXIQUE[randint(0, taille)]) + for n in range(hors): + while True: + mot = motAleatoire(randint(0, 10)) + if mot not in LEXIQUE: + break + elements.append(mot) return elements # Méthode de test des fonctions @@ -153,3 +165,9 @@ if __name__ == '__main__': mesure(seq, LEXIQUE, exclu) mesure(seqTrie, LEXIQUE_TRIE, exclu) mesure(dicho, LEXIQUE_TRIE, exclu) + + print("\nTest avec 500 éléments dont 80% sont dans LEXIQUE") + exclu = creerListeRecherche(LEXIQUE, 400, 100) + mesure(seq, LEXIQUE, exclu) + mesure(seqTrie, LEXIQUE_TRIE, exclu) + mesure(dicho, LEXIQUE_TRIE, exclu)