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

This commit is contained in:
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

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