Use random.choices instead of random.choice in a loop.
This commit is contained in:
parent
13bf8e2e47
commit
c65743ec02
1 changed files with 2 additions and 2 deletions
|
@ -116,7 +116,7 @@ def make_password(length=None, passtype='standard'):
|
||||||
random.shuffle(alphabet)
|
random.shuffle(alphabet)
|
||||||
password += alphabet.pop(0)
|
password += alphabet.pop(0)
|
||||||
else:
|
else:
|
||||||
password = ''.join([random.choice(alphabet) for x in range(length)])
|
password = ''.join(random.choices(alphabet, k=length))
|
||||||
return password
|
return password
|
||||||
|
|
||||||
def make_sentence(length=None, joiner=' '):
|
def make_sentence(length=None, joiner=' '):
|
||||||
|
@ -127,7 +127,7 @@ def make_sentence(length=None, joiner=' '):
|
||||||
import dictionary.common as common
|
import dictionary.common as common
|
||||||
if length is None:
|
if length is None:
|
||||||
length = DEFAULT_LENGTH
|
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]
|
words = [w.replace(' ', joiner) for w in words]
|
||||||
result = joiner.join(words)
|
result = joiner.join(words)
|
||||||
return result
|
return result
|
||||||
|
|
Loading…
Reference in a new issue