You can download this code by clicking the button below.
This code is now available for download.
This function generates a random filename with a prefix, random characters, and a file extension.
Technology Stack : os, sys, time, random
Code Type : Function
Code Difficulty : Intermediate
import os
import sys
import time
import random
def generate_random_filename(prefix="random_", extension=".txt"):
characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
filename = prefix + ''.join(random.choice(characters) for _ in range(10)) + extension
return filename