File: names.py

package info (click to toggle)
freeorion 0.5.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 194,940 kB
  • sloc: cpp: 186,508; python: 40,969; ansic: 1,164; xml: 719; makefile: 32; sh: 7
file content (27 lines) | stat: -rw-r--r-- 787 bytes parent folder | download
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
import freeorion as fo
import random
from itertools import cycle

# tuples of consonants and vowels for random name generation
consonants = ("b", "c", "d", "f", "g", "h", "j", "k", "l", "m", "n", "p", "q", "r", "s", "t", "v", "w", "x", "y", "z")
vowels = ("a", "e", "i", "o", "u")


_random_letter_generator = (random.choice(x) for x in cycle((consonants, vowels)))


def random_name(size):
    """
    Return random name of given size.

    It rotates between consonants and vowels.
    Rotation is global first letter depends on prev calls.
    """
    return "".join(next(_random_letter_generator) for _ in range(size)).capitalize()


def get_name_list(name_list):
    """
    Retrieves a list of names from the string tables.
    """
    return fo.userString(name_list).splitlines()