From 6e88d38f51f456e2a933b86a1c70be291cd8ccc3 Mon Sep 17 00:00:00 2001 From: YuCheng Hu Date: Thu, 18 Mar 2021 08:10:12 -0400 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=94=9F=E6=88=90=E9=9A=8F?= =?UTF-8?q?=E6=9C=BA=E5=AD=97=E7=AC=A6=E4=B8=B2=E7=9A=84=20Python=20?= =?UTF-8?q?=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/RandomStringGenerate.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 tests/RandomStringGenerate.py diff --git a/tests/RandomStringGenerate.py b/tests/RandomStringGenerate.py new file mode 100644 index 0000000..f7b9c0a --- /dev/null +++ b/tests/RandomStringGenerate.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- + +# Python Random String Password +# Author - https://www.ossez.com + +import string +from random import choice + + +def random_password(length, printable): + """ + 根据给定的字符串长度和可以用于生成字符串的字符集来生成随机字符串 + :param printable: 可用于生成随机字符串的字符 + :param int length: 生成随机字符串的数量 + """ + + return "".join([choice(printable) for x in range(int(length))]) + + +if __name__ == "__main__": + 3 + +amount = int(input("请输入需要生成随机字符串的数量: ")) +number = int(input("请输入随机字符串的长度: ")) + +for i in range(1, amount + 1): + print(f" 随机字符串 [Printable String]: {i} - {repr(random_password(number, string.printable))} ") + +print('') +for i in range(1, amount + 1): + print(f" 随机字符串 [Ascii Uppercase String]: {i} - {repr(random_password(number, string.ascii_uppercase))} ")