You can download this code by clicking the button below.
This code is now available for download.
This function is used to generate a random string of specified length using the random and string built-in libraries.
Technology Stack : random, string
Code Type : Function
Code Difficulty : Intermediate
import random
import string
import os
import re
import sys
import json
def generate_random_string(length):
"""
生成指定长度的随机字符串。
Args:
length (int): 随机字符串的长度。
Returns:
str: 生成的随机字符串。
"""
return ''.join(random.choices(string.ascii_letters + string.digits, k=length))