samedi 15 février 2020

Does random.seed() work only for numbers?

I'm doing an assignment:

Write a program that randomly generates a nine-character password. First 3 characters must be from the set "let", second 3 characters from the set "num", last three ones from the set "sym". Set seed() to 42 and generate a password.

This is my code:

import random
let= {'A','B','C','a','b','c'}
letnew=""
for i in let:
    letnew=letnew+i
print(letnew)

num = {1,2,3,4,5,6}
numnew=""
for i in num:
    numnew=numnew+str(i)
print(numnew)
sym = {'!','@','#','$','%','^'}
symnew=""
for i in sym:
    symnew=symnew+i
print(symnew)

password=""
random.seed(42)
password=random.choices(letnew, k=3)+random.choices(numnew, k=3)+random.choices(symnew, k=3)
print(password)

I tried many ways, but I have to use random.seed(). But what I see is that it works only for the set num. I don't get what is the problem or if there is another better solution.




Aucun commentaire:

Enregistrer un commentaire