You can download this code by clicking the button below.
This code is now available for download.
Generate a random string of a specified length.
Technology Stack : random, string
Code Type : Function
Code Difficulty : Intermediate
import random
import math
import os
import sys
import datetime
import json
import re
def generate_random_string(length, characters='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'):
return ''.join(random.choice(characters) for _ in range(length))
def main():
random_string = generate_random_string(10)
print(random_string)
print(json.dumps({"value": random_string}))
def generate_random_string(length, characters='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'):
return ''.join(random.choice(characters) for _ in range(length))