Random Word Generator Function

  • Share this:

Code introduction


This function generates a specified number of random words, with each word's length specified by the user.


Technology Stack : The Textual library is not used, and the packages and technologies used include: random (used for randomly selecting characters), string (provides string constants and methods)

Code Type : Function

Code Difficulty : Intermediate


                
                    
def random_word_generator(num_words, word_length):
    import random
    import string
    
    def generate_word(word_length):
        return ''.join(random.choices(string.ascii_lowercase, k=word_length))
    
    return [generate_word(word_length) for _ in range(num_words)]