Skip to content

Instantly share code, notes, and snippets.

@walbon
Created February 21, 2024 17:35
Show Gist options
  • Save walbon/3ece622862bec998fabf6a5814836f9f to your computer and use it in GitHub Desktop.
Save walbon/3ece622862bec998fabf6a5814836f9f to your computer and use it in GitHub Desktop.
import random
adjectives = [
"blue", "red", "green", "yellow", "purple", "orange",
"happy", "sad", "angry", "calm", "sleepy", "hungry",
"big", "small", "tall", "short", "wide", "narrow",
"soft", "hard", "rough", "smooth", "hot", "cold",
]
nouns = [
"bird", "cat", "dog", "fish", "mouse", "snake",
"tree", "flower", "grass", "mountain", "river", "ocean",
"house", "car", "boat", "plane", "train", "bus",
"computer", "phone", "book", "pencil", "paper", "chair",
]
def generate_name():
"""Generates a random name using an adjective and a noun."""
adjective = random.choice(adjectives)
noun = random.choice(nouns)
return f"{adjective}-{noun}"
def random_name_generator():
"""Infinitely yields random names."""
while True:
yield generate_name()
# Example usage
for name in random_name_generator():
print(name)
# Example output: blue-bird, red-cat, green-dog, ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment