My code basically picks random letters and numbers from three lists and makes a random combination with them. I decided to write this code just for fun, however I feel like the code can be made shorter. I just don't know how.
So here is my code:
import random
caps=['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
numbers=['1','2','3','4','5','6','7','8','9','0']
letters=['a','b','c','d','e','f','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
for j in range (4):
lengthcaps=len(caps)
indexcaps=random.randint(0, lengthcaps)
fillcaps=caps[indexcaps-1]
lengthnumbers=len(numbers)
indexnumbers=random.randint(0, lengthnumbers)
fillnumber=numbers[indexnumbers-1]
lengthletters=len(letters)
indexletters=random.randint(0, lengthletters)
fillletter=letters[indexletters-1]
list=[fillletter,fillcaps,fillnumber]
index1list=random.randint(0,2)
index2list=random.randint(0,2)
index3list=random.randint(0,2)
index4list=random.randint(0,2)
index5list=random.randint(0,2)
index6list=random.randint(0,2)
fill1list=list[index1list]
fill2list=list[index2list]
fill3list=list[index3list]
fill4list=list[index4list]
fill5list=list[index5list]
fill6list=list[index6list]
print(fill1list + fill2list + fill3list + fill4list + fill5list + fill6list)
If this is duplicate, please feel free to tell me, because searching for things isn't one of my qualities.
secrets
module instead ofrandom
\$\endgroup\$secrets
module provides a cryptographically strong source of randomness, meaning that even if you know the last x output values of the random number generator, it is practically impossible to compute its internal state, so the next output is always unpredictable. That's not the case for therandom
module, which is the reason why it shouldn't be used for security purposes \$\endgroup\$