Random Word Generator with Specified Length

  • 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 directly, but the random and string modules are used.

Code Type : Function

Code Difficulty : Intermediate


                
                    
def random_word_generator(num_words, word_length):
    import random
    import string

    def generate_word(length):
        return ''.join(random.choices(string.ascii_letters, k=length))

    return [generate_word(word_length) for _ in range(num_words)]