Random Word Generator Function

  • Share this:

Code introduction


This function generates a series of random words based on the given number of words and length range.


Technology Stack : random, string

Code Type : The type of code

Code Difficulty : Intermediate


                
                    
def random_word_generator(num_words, min_length, max_length):
    import random
    import string
    words = []
    for _ in range(num_words):
        word_length = random.randint(min_length, max_length)
        word = ''.join(random.choices(string.ascii_lowercase, k=word_length))
        words.append(word)
    return words                
              
Tags: