Answer the question
In order to leave comments, you need to log in
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
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:] # обрезане префикса до максимальной длинны
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]
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.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question