Use random.choices instead of random.choice in a loop.

master
voussoir 2021-08-09 08:33:02 -07:00
parent 13bf8e2e47
commit c65743ec02
No known key found for this signature in database
GPG Key ID: 5F7554F8C26DACCB
1 changed files with 2 additions and 2 deletions

View File

@ -116,7 +116,7 @@ def make_password(length=None, passtype='standard'):
random.shuffle(alphabet)
password += alphabet.pop(0)
else:
password = ''.join([random.choice(alphabet) for x in range(length)])
password = ''.join(random.choices(alphabet, k=length))
return password
def make_sentence(length=None, joiner=' '):
@ -127,7 +127,7 @@ def make_sentence(length=None, joiner=' '):
import dictionary.common as common
if length is None:
length = DEFAULT_LENGTH
words = [random.choice(common.words) for x in range(length)]
words = random.choices(common.words, k=length)
words = [w.replace(' ', joiner) for w in words]
result = joiner.join(words)
return result