← All Workshops

MudEngine Part 6: Multiplayer

Step 10 / 18

Random Name Generator

Every new player needs a name. Rather than force the player to invent one, the game pre-fills the name input with a fun randomly generated name.

The random_name function derives a name from the bytes of a fresh Uuid:

  • The first byte picks an adjective (ADJS).
  • The second byte picks a noun (NOUNS).
  • They're combined into something like Great Dragon or Sly Fae.

A new Uuid is generated on every call, so refreshing the page yields a different name. Nothing is stored yet — the generated name just seeds the player_name signal until the player types over it.

Create src/game/random_name.rs with this helper. It is pub because the App component calls it to seed the name field.

mud-engine/src/game/random_name.rs
// ── Name Registration ──

pub fn random_name() -> String {
    let id = uuid::Uuid::new_v4();
    const ADJS: [&str; 10] = [
        "Great", "Intelligent", "Cute", "Brave", "Mighty",
        "Sly", "Ancient", "Mysterious", "Swift", "Gentle",
    ];
    const NOUNS: [&str; 10] = [
        "Dragon", "Elf", "Phoenix", "Goblin", "Griffin",
        "Unicorn", "Wizard", "Knight", "Wyrm", "Fae",
    ];
    let adj = ADJS[id.as_bytes()[0] as usize % 10];
    let noun = NOUNS[id.as_bytes()[1] as usize % 10];
    format!("{} {}", adj, noun)
}
Step 10 / 18