68 lines
3.2 KiB
Python
Executable File
68 lines
3.2 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
# namegen - generate creative names for projects, pets, or bands from combinable word lists
|
|
# Usage: namegen [--kind project|pet|band] [--count N] [--seed N]
|
|
import argparse, random, sys
|
|
|
|
ADJ = ["cosmic", "silent", "electric", "midnight", "golden", "rapid", "velvet",
|
|
"crimson", "lunar", "solar", "iron", "crystal", "neon", "shadow", "brave",
|
|
"clever", "happy", "wild", "gentle", "stormy", "frosty", "ember", "quantum"]
|
|
PROJECT_NOUNS = ["falcon", "compass", "lantern", "rocket", "harbor", "bridge",
|
|
"forge", "atlas", "beacon", "cipher", "engine", "garden", "horizon",
|
|
"keystone", "lighthouse", "meadow", "notebook", "orchard", "pilot", "quill"]
|
|
PET_NAMES = ["Biscuit", "Mochi", "Pickles", "Waffles", "Ziggy", "Clover", "Peanut",
|
|
"Noodle", "Maple", "Oreo", "Pumpkin", "Simba", "Tofu", "Winston", "Zelda"]
|
|
PET_ADJ = ["Sir", "Captain", "Professor", "Duke", "Lady", "Major", "Doctor", "Baron"]
|
|
BAND_ADJ = ["electric", "midnight", "velvet", "crimson", "neon", "cosmic", "rusty",
|
|
"silent", "burning", "hollow", "wild", "golden"]
|
|
BAND_NOUNS = ["wolves", "mirrors", "thunder", "ghosts", "rivers", "sparks", "dragons",
|
|
"echoes", "tigers", "comets", "ravens", "storms", "lanterns", "foxes"]
|
|
|
|
def gen(kind, rng):
|
|
if kind == "pet":
|
|
style = rng.random()
|
|
if style < 0.5:
|
|
return rng.choice(PET_NAMES)
|
|
return f"{rng.choice(PET_ADJ)} {rng.choice(PET_NAMES)}"
|
|
if kind == "band":
|
|
if rng.random() < 0.7:
|
|
return f"The {rng.choice(BAND_ADJ).title()} {rng.choice(BAND_NOUNS).title()}"
|
|
return f"{rng.choice(BAND_ADJ).title()} {rng.choice(BAND_NOUNS).title()}"
|
|
# project: adjective + noun, sometimes with a suffix
|
|
name = f"{rng.choice(ADJ)}-{rng.choice(PROJECT_NOUNS)}"
|
|
if rng.random() < 0.2:
|
|
name += rng.choice(["-labs", "-hq", "2", "-x", "-pro"])
|
|
return name
|
|
|
|
def selftest():
|
|
rng = random.Random(11)
|
|
for kind in ("project", "pet", "band"):
|
|
names = [gen(kind, rng) for _ in range(5)]
|
|
assert all(names) and len(set(names)) >= 3, (kind, names)
|
|
print(f"{kind}: " + ", ".join(names))
|
|
assert gen("project", random.Random(1)) == gen("project", random.Random(1))
|
|
print("namegen selftest OK")
|
|
|
|
def main():
|
|
p = argparse.ArgumentParser(description="Generate creative names for projects, pets, or bands from combinable word lists.")
|
|
p.add_argument("--kind", choices=["project", "pet", "band"], default="project",
|
|
help="kind of name (default project)")
|
|
p.add_argument("--count", type=int, default=5, help="how many names (default 5)")
|
|
p.add_argument("--seed", type=int, default=None, help="seed for deterministic output")
|
|
p.add_argument("--selftest", action="store_true", help="run a built-in self-test and exit")
|
|
a = p.parse_args()
|
|
if a.selftest:
|
|
selftest(); return 0
|
|
rng = random.Random(a.seed)
|
|
seen = set()
|
|
for _ in range(max(1, a.count)):
|
|
for _attempt in range(20):
|
|
name = gen(a.kind, rng)
|
|
if name not in seen:
|
|
break
|
|
seen.add(name)
|
|
print(name)
|
|
return 0
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|