更新使用 choices 函数的测试
This commit is contained in:
parent
c3fdd5ac02
commit
2ea753ac1d
|
@ -5,7 +5,7 @@
|
||||||
# Link Article - https://www.ossez.com/t/python/13398
|
# Link Article - https://www.ossez.com/t/python/13398
|
||||||
|
|
||||||
import string
|
import string
|
||||||
from random import choice
|
import random
|
||||||
|
|
||||||
|
|
||||||
def random_password(length, printable):
|
def random_password(length, printable):
|
||||||
|
@ -15,7 +15,7 @@ def random_password(length, printable):
|
||||||
:param int length: 生成随机字符串的数量
|
:param int length: 生成随机字符串的数量
|
||||||
"""
|
"""
|
||||||
|
|
||||||
return "".join([choice(printable) for x in range(int(length))])
|
return "".join([random.choice(printable) for x in range(int(length))])
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
@ -39,3 +39,8 @@ for i in range(1, amount + 1):
|
||||||
print('')
|
print('')
|
||||||
for i in range(1, amount + 1):
|
for i in range(1, amount + 1):
|
||||||
print(f" 随机字符串 [Ascii Digits String]: {i} - {repr(random_password(number, string.digits))} ")
|
print(f" 随机字符串 [Ascii Digits String]: {i} - {repr(random_password(number, string.digits))} ")
|
||||||
|
|
||||||
|
# choices Function Test
|
||||||
|
print('')
|
||||||
|
my_list = ["apple", "banana", "cherry"]
|
||||||
|
print(random.choices(my_list, weights=[10, 1, 1], k=12))
|
||||||
|
|
Loading…
Reference in New Issue