creating a simple pass generator for myself, i noticed that if i want my population to be digits only (0-9) which is overall 10 options, if i want my length over 10, it wont use any of the digits more then once and return the "sample larger then population" error.
is it possible to maintain the code, but add/reduce code lines so it works? or do i HAVE To use a use random choice?
import string
import random
z=int(raw_input("for:
numbers only choose 1,
letters only choose 2,
letters and numbers choose 3,
for everything choose 4:"))
if z==1:
x=string.digits
elif z==2:
x=string.letters
elif z==3:
x=string.letters+string.digits
elif z==4:
x=string.letters+string.digits+string.punctuation
else:
print "die in a fire"
y=int(raw_input("How many passwords would you like?:"))
v=int(raw_input("How long would you like the password to be?:"))
for i in range(y):
string=""
for n in random.sample(x,v):
string+=n
print string
ty
See Question&Answers more detail:os