mercredi 23 décembre 2020

How to select random characters in a non-unique way

Alright, I have a password generator, The code I have is this:

password=random.sample(chars,letters) #chars is a list of Characters (symbols,letters,numbers) and letters is how many letters are in the password
divider = ""
password = divider.join(password) 
print(password,flush=True, end=inbetween) #inbetween is where the user can choose what character seperates the passwords (it can print multiple passwords)

The issue I have is that random.sample only selects unique characters. Is there an alternative function that does the same as random.sample, but can select non-unique characters from the list.

By the way, Here is the values for the variable chars:

chars= ["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","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","$","%","&","(",")","*",",","-",".","/",":",";","<","=",">","?","@","[","]","^","_","`","{","|","}","~","0","1","2","3","4","5","6","7","8","9"]



Aucun commentaire:

Enregistrer un commentaire