You can download this code by clicking the button below.
This code is now available for download.
Generate a random string of specified length.
Technology Stack : random, string
Code Type : Function
Code Difficulty : Intermediate
import random
import math
import string
import os
import sys
import hashlib
import time
def generate_random_string(length=10):
return ''.join(random.choices(string.ascii_letters + string.digits, k=length))
def calculate_hypotenuse(a, b):
return math.sqrt(a**2 + b**2)
def list_directory_content(path='.'):
return os.listdir(path)
def print_system_info():
return sys.version
def hash_string(input_string, algorithm='sha256'):
return hashlib.new(algorithm, input_string.encode()).hexdigest()
def sleep_for_seconds(seconds):
time.sleep(seconds)
def create_directory(path):
os.makedirs(path, exist_ok=True)
def remove_directory(path):
os.rmdir(path)