File size: 2,152 Bytes
de132df
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import random
import fictional_names.tolkien as tolkien
import fictional_names.viking as viking
import fictional_names.rowling as rowling

def generate_fantasy_name(race, gender=None):
    """Generates a random fantasy name based on race using fictional-names library data."""
    
    race = race.lower()
    
    # Mapping our app's races to library components
    if "human" in race:
        # Use full names for humans as they are already diverse
        source = viking
    elif any(r in race for r in ["elf", "elven"]):
        # Tolkien elven feel
        source = tolkien
    elif "dwarf" in race:
        # Tolkien dwarven feel
        source = tolkien
    elif "orc" in race:
        # Tolkien orcish feel
        source = tolkien
    elif any(r in race for r in ["tiefling", "dragonborn"]):
        # Rowling components have a more exotic/latinate feel
        source = rowling
    else:
        # Default fallback
        source = tolkien

    # Decide gender list
    if gender and gender.lower() == "female":
        prefixes = source.female_prefix
        suffixes = source.female_suffix
        names = source.female_names
    elif gender and gender.lower() == "male":
        prefixes = source.male_prefix
        suffixes = source.male_suffix
        names = source.male_names
    else:
        # Combine both for 'any'
        prefixes = source.male_prefix + source.female_prefix
        suffixes = source.male_suffix + source.female_suffix
        names = source.male_names + source.female_names

    # Use a mix of full names and generated ones for maximum variety
    if random.random() > 0.4 and names:
        first_name = random.choice(names)
    else:
        # Generate from syllables
        prefix = random.choice(prefixes) if prefixes else "Al"
        suffix = random.choice(suffixes) if suffixes else "en"
        first_name = (prefix + suffix).capitalize()

    # Surnames (if available in the source)
    surname = ""
    if hasattr(source, "surnames") and random.random() > 0.3:
        surname = random.choice(source.surnames)
    
    if surname:
        return f"{first_name} {surname}"
    
    return first_name