Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Name generation unit
- markov = {
- -- Set of working letters and digits ('#' and '$' represents starting and ending word boundary respectively)
- letters = {
- 'a', 'b', 'c', 'd', 'e',
- 'f', 'g', 'h', 'i', 'j',
- 'k', 'l', 'm', 'n', 'o',
- 'p', 'q', 'r', 's', 't',
- 'u', 'v', 'w', 'x', 'y',
- 'z', 'A', 'B', 'C', 'D',
- 'E', 'F', 'G', 'H', 'I',
- 'J', 'K', 'L', 'M', 'N',
- 'O', 'P', 'Q', 'R', 'S',
- 'T', 'U', 'V', 'W', 'X',
- 'Y', 'Z', ' ', '-', '_',
- '#', '$'
- },
- -- The dictionary itself
- dictionary = {},
- -- Creates the dictionary setting all letter transitions to zero
- createdictionary = function(athis)
- local lletter1, lletter2
- for lletter1 = 1, 57 do
- for lletter2 = 1, 57 do
- print('Setting frequency of : ' .. letters[lletter1] .. ' -> ' .. letters[lletter2] .. ' to zero.')
- athis.dictionary[letters[lletter1] .. letters[lletter2]] = 0
- end
- end
- end,
- -- Increases the frequency of a certain letter transition
- increasefrequency = function(athis, aletter1, aletter2)
- print('Increase frequency of : ' .. aletter1 .. ' -> ' .. aletter2)
- athis.dictionary[aletter1 .. aletter2] = athis.dictionary[aletter1 .. aletter2] + 1
- end,
- -- Normalizes all letter frequencies to within 0..100 range
- normalizefrequencies = function(athis, aletter1, aletter2)
- local lmax = 0
- local lmin = 0
- local lletter1, lletter2
- for lletter1 = 1, 57 do
- for lletter2 = 1, 57 do
- if athis.dictionary[letters[lletter1] .. letters[lletter2]] > lmax then
- lmax = athis.dictionary[letters[lletter1] .. letters[lletter2]]
- elseif athis.dictionary[letters[lletter1] .. letters[lletter2]] > lmin then
- lmin = athis.dictionary[letters[lletter1] .. letters[lletter2]]
- else
- end
- end
- end
- local lsize = lmax - lmin
- local lratio = lsize / 100
- for lletter1 = 1, 57 do
- for lletter2 = 1, 57 do
- athis.dictionary[letters[lletter1] .. letters[lletter2]] = athis.dictionary[letters[lletter1] .. letters[lletter2]] / lratio
- end
- end
- end,
- -- Adds a word to the dictionary, increasing the letters transitions accordingly
- addword = function(athis, aword)
- local lword = '#' .. aword .. '$'
- print('Adding word to the dictionary : ' .. lword)
- for lchar = 1, strlen(lword) - 1 do
- athis:increasefrequency(string.sub(lword, lchar, 2))
- end
- end,
- -- Gets a row of frequencies from a certain letter aletter towards each other letter frequency
- -- Applies a random factor to their frequencies
- getfrequencies = function(athis, aletter)
- local result = {}
- for lletter = 1, 57 do
- local freq = athis.dictionary[aletter .. letters[lletter]]
- print('Frequency of ' .. aletter .. ' -> ' .. letters[lletter] .. ' is ' .. freq)
- result[letters[lletter]] = freq * math.random() * math.random(25)
- end
- end,
- -- Get the most probably next letter from a certain letter
- getnextletter = function(athis, astartingletter)
- local lfreq = athis:getfrequencies(astartingletter)
- local selletter = '$'
- local selletterfreq = -100
- for lletter = 1, 57 do
- if lfreq[letters[lletter]] > selletterfreq then
- selletter = letters[lletter]
- selletterfreq = lfreq[letters[lletter]]
- end
- end
- end,
- -- Concatenates a letter into a word
- appendletter = function(athis, alump, anextletter)
- if anextletter = '#' then
- elseif anextletter = '$' then
- else
- return alump .. anextletter
- end
- end,
- -- Generates a new word
- generateword = function(athis)
- local lnextletter = athis.letters[math.random(57)]
- while lnextletter = '#' or lnextletter = '$' do
- lnextletter = athis.letters[math.random(57)]
- end
- local lword = ''
- while lnextletter ~= '$' do
- athis:appendletter(lword, lnextletter)
- lnextletter = athis:getnextletter(lnextletter)
- end
- return lword
- end
- }
RAW Paste Data