R
R
Rrooom2014-09-13 23:10:11
Python
Rrooom, 2014-09-13 23:10:11

How to generate random names?

For the game, I would like to offer the generation of random names (elven and orcish). I started looking at numerous sites - everywhere a banal random choice from a large, but not immense list.
How would you generate them? Something in my head is spinning about Markov chains... But...

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Maxim Vasiliev, 2014-09-14
@Rrooom

Markov chains will help to calculate the compatibility of letters in names, and choose the most "elegant" letter according to the context (prefix).
The method is extremely efficient and can generate an infinite number of words.
But only if the training sample is large enough.
My recommendation:
Use a prefix length of 3-4 letters (about the length of a syllable).
Longer prefixes will generate words that are too similar to the original and their recombinations.
Shorter ones will not sound very euphonious.
Be sure to use the characters of the beginning and end of the word as a special letter ('^' and '$'), just a space is not enough, but I don't remember why.
For names, it makes sense to generate them from the end, since the endings of the names are specific, and random may not fall on the end chain for a long time, generating unnecessarily long words. And when generating from the end, you can simply cut off the word by the critical length, or get off at the nearest stop.
For storage, it is efficient to use a prefix tree with frequencies as values.
The algorithm for compiling a dictionary is quite simple:

prefix = '^'
for letter in text:
  freqdict[prefix+ letter] += 1 # увеличение счётчика этого сочетания
  if letter ='$':  # конец слова, сброс префикса
    prefix = '^'
  else:
    prefix = prefix[-depdth:] # обрезане префикса до максимальной длинны

After that, you need to normalize the values ​​for each prefix so that
for each prefix the sum of the values ​​of all tails is = 1.
In this scenario, you can "glue" the frequencies into a single segment, divided into parts in proportion to the frequency, and randomly choose "weighted uniformly".
Generation algorithm:
prefix = '^'
while prefix[-1] != '$':
  tails = freqdict[prefix].items() # под-дерево всех продолжений префикса в виде списка (key, value)
  thresh = random() # точка на единичном отрезке
  i = 0 # текущий элемент
  level = 0 # верхняя граница отрезка текущего элемента
  while thresh > level:
    level += tails[i][1]
    i++
  prefix += tails[i][0]

The code is written from memory, don't take my word for it :)
Probably, it's time for me to upload the library for fish generation...

S
Sali_cat, 2014-09-14
@Sali_cat

Use a random number generator, only in names.
Or a handicap cycle, there are many options to be honest. Yes, and it depends on the language in which you wrote?
This is not at all a question that cannot be answered. 5 minutes of searching and that's it.

A
andy-007, 2014-09-14
@andy-007

yes, it seems that not so long ago there was just such a site with a nickname generator, although all of them are in an oriental way, but nevertheless ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question