diff --git a/tests/RandomStringGenerate.py b/tests/RandomStringGenerate.py index c5de637..b158f7b 100644 --- a/tests/RandomStringGenerate.py +++ b/tests/RandomStringGenerate.py @@ -5,7 +5,7 @@ # Link Article - https://www.ossez.com/t/python/13398 import string -from random import choice +import random def random_password(length, printable): @@ -15,7 +15,7 @@ def random_password(length, printable): :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__": @@ -39,3 +39,8 @@ for i in range(1, amount + 1): print('') for i in range(1, amount + 1): 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))