You can download this code by clicking the button below.
This code is now available for download.
This function generates a random string of a specified length composed of uppercase and lowercase letters.
Technology Stack : string
Code Type : Function
Code Difficulty :
import datetime
import json
import os
import random
import re
import string
import sys
import time
def generate_random_string(length=10):
"""生成一个指定长度的随机字符串。
Args:
length (int): 字符串的长度,默认为10。
Returns:
str: 生成的随机字符串。
"""
letters = string.ascii_letters
return ''.join(random.choice(letters) for i in range(length))