Random String Generator

  • Share this:

Code introduction


Generate a random string of a specified length containing both uppercase and lowercase letters and numbers.


Technology Stack : math, os, random, string, datetime, heapq

Code Type : Function

Code Difficulty : Intermediate


                
                    
import math
import os
import random
import string
import datetime
import heapq

def random_string(length=10):
    return ''.join(random.choices(string.ascii_letters + string.digits, k=length))