- Joined
- Apr 24, 2012
- Messages
- 5,111
I created this simple name generator that follows a set of rules for creating names, such as if a generated character is p as a beginning character, it can only be proceeded with consonants h, l and r.
I based this mostly on the english language but meh, you can't even distinguish what language is the structure based upon :v
Note: there are still some bugs and things that are working wrong.
I based this mostly on the english language but meh, you can't even distinguish what language is the structure based upon :v
JASS:
constant function NAME_GENERATOR_VOWELS takes nothing returns string
return "aeiouy"
endfunction
constant function NAME_GENERATOR_CONSONANTS takes nothing returns string
return "bcdfghjklmnprstvwz"
endfunction
constant function NAME_GENERATOR_VLENGTH takes nothing returns integer
return 6
endfunction
constant function NAME_GENERATOR_CLENGTH takes nothing returns integer
return 18
endfunction
function NAME_GENERATOR_RULES takes nothing returns nothing
set udg_NG_StartRules[1] = "hlr"
set udg_NG_StartRules[2] = "th"
set udg_NG_StartRules[3] = "rh"
set udg_NG_StartRules[4] = "hlrw"
set udg_NG_StartRules[5] = "hrw"
set udg_NG_StartRules[6] = "h"
set udg_NG_StartRule[1] = udg_NG_StartRules[1]
set udg_NG_StartRule[2] = udg_NG_StartRules[1]
set udg_NG_StartRule[3] = udg_NG_StartRules[5]
set udg_NG_StartRule[4] = udg_NG_StartRules[1]
set udg_NG_StartRule[5] = udg_NG_StartRules[1]
set udg_NG_StartRule[6] = udg_NG_StartRules[6]
set udg_NG_StartRule[7] = udg_NG_StartRules[6]
set udg_NG_StartRule[8] = udg_NG_StartRules[4]
set udg_NG_StartRule[9] = udg_NG_StartRules[6]
set udg_NG_StartRule[10] = udg_NG_StartRules[6]
set udg_NG_StartRule[11] = udg_NG_StartRules[6]
set udg_NG_StartRule[12] = udg_NG_StartRules[1]
set udg_NG_StartRule[13] = udg_NG_StartRules[1]
set udg_NG_StartRule[14] = udg_NG_StartRules[6]
set udg_NG_StartRule[15] = udg_NG_StartRules[1]
set udg_NG_StartRule[16] = udg_NG_StartRules[1]
set udg_NG_StartRule[17] = udg_NG_StartRules[3]
set udg_NG_StartRule[18] = udg_NG_StartRules[6]
set udg_NG_EndRules[1] = "s"
set udg_NG_EndRules[2] = "tmns"
set udg_NG_EndRules[3] = "cdstk"
set udg_NG_EndRules[4] = "sk"
set udg_NG_EndRules[5] = "h"
set udg_NG_EndRules[6] = "sh"
set udg_NG_EndRules[7] = "shtk"
set udg_NG_EndRules[8] = "tmnsk"
set udg_NG_EndRules[9] = "bs"
set udg_NG_EndRules[10] = "r"
set udg_NG_EndRule[1] = udg_NG_EndRules[1]
set udg_NG_EndRule[2] = udg_NG_EndRules[7]
set udg_NG_EndRule[3] = udg_NG_EndRules[1]
set udg_NG_EndRule[4] = udg_NG_EndRules[1]
set udg_NG_EndRule[5] = udg_NG_EndRules[6]
set udg_NG_EndRule[6] = udg_NG_EndRules[10]
set udg_NG_EndRule[8] = udg_NG_EndRules[6]
set udg_NG_EndRule[9] = udg_NG_EndRules[2]
set udg_NG_EndRule[10] = udg_NG_EndRules[9]
set udg_NG_EndRule[11] = udg_NG_EndRules[3]
set udg_NG_EndRule[12] = udg_NG_EndRules[6]
set udg_NG_EndRule[14] = udg_NG_EndRules[8]
set udg_NG_EndRule[15] = udg_NG_EndRules[6]
set udg_NG_EndRule[16] = udg_NG_EndRules[1]
set udg_NG_EndRule[17] = udg_NG_EndRules[4]
set udg_NG_EndRule[18] = udg_NG_EndRules[5]
set udg_NG_VowelRule[1] = "eiouy"
set udg_NG_VowelRule[2] = "aiouy"
set udg_NG_VowelRule[3] = "aeou"
set udg_NG_VowelRule[4] = "aeiouy"
set udg_NG_VowelRule[5] = "aeioy"
set udg_NG_VowelRule[6] = "aeiou"
endfunction
function NG_FindLetter takes string s, string toFind returns integer
local integer i = 0
local integer l = StringLength(s)
loop
exitwhen i == l
set i = i + 1
if SubString(s, i - 1, i) == toFind then
return i
endif
endloop
return -1
endfunction
function GenerateName takes integer length returns string
local integer i = 0
local string result = ""
local string temp
local string tempChar
local integer tempInt
local integer tempL
local integer id
local boolean doC = false
local string prevChar = ""
local integer cStack = 0
local integer vStack = 0
local integer chance = 0
if udg_NG_StartRules[1] == "" or udg_NG_EndRules[1] == "" then
call NAME_GENERATOR_RULES()
endif
loop
exitwhen i >= length
set i = i + 1
set doC = GetRandomInt(1, 2) == 1
if cStack >= 2 then
set doC = false
elseif vStack >= 2 then
set doC = true
endif
if doC then
if i == 2 then
set id = NG_FindLetter(NAME_GENERATOR_CONSONANTS(), temp)
set tempInt = GetRandomInt(0, StringLength(udg_NG_StartRule[id]) - 1)
set temp = SubString(udg_NG_StartRule[id], tempInt, tempInt + 1)
elseif i == length - 1 then
set id = NG_FindLetter(NAME_GENERATOR_CONSONANTS(), temp)
if udg_NG_EndRule[id] != "" then
set tempInt = GetRandomInt(0, StringLength(udg_NG_EndRule[id]) - 1)
set temp = SubString(udg_NG_EndRule[id], tempInt, tempInt + 1)
else
set i = i - 1
set cStack = cStack - 1
endif
else
set tempInt = GetRandomInt(0, NAME_GENERATOR_CLENGTH() - 1)
set temp = SubString(NAME_GENERATOR_CONSONANTS(), tempInt, tempInt + 1)
endif
set cStack = cStack + 1
set vStack = 0
else
if vStack == 0 then
set tempInt = GetRandomInt(0, NAME_GENERATOR_VLENGTH() - 1)
set temp = SubString(NAME_GENERATOR_VOWELS(), tempInt, tempInt + 1)
else
set id = NG_FindLetter(NAME_GENERATOR_VOWELS(), temp)
set tempInt = GetRandomInt(0, StringLength(udg_NG_VowelRule[id]) - 1)
set temp = SubString(udg_NG_VowelRule[id], tempInt, tempInt + 1)
endif
set vStack = vStack + 1
set cStack = 0
endif
set result = result + temp
endloop
return result
endfunction
Note: there are still some bugs and things that are working wrong.