Random Word String Generator

  • Share this:

Code introduction


The function generates a random string of words, composed of multiple randomly selected words, with customizable number and length of words.


Technology Stack : Typer

Code Type : Function

Code Difficulty : Intermediate


                
                    
import random

def random_word_generator(num_words=5, word_length=8):
    """
    Generate a random string of words.
    """
    words = ["apple", "banana", "cherry", "date", "elderberry", "fig", "grape", "honeydew"]
    random_words = " ".join(random.choices(words, k=num_words))
    return random_words                
              
Tags: