Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local con = {"b","c","d","f","g","h","j","k","l","m","n","p","q","r","s","t","v","w","x","y","z"}
- local vow = {"a","e","i","o","u"}
- local maxLength = 8
- local function hasValue (tab, val)
- for index, value in ipairs(tab) do
- if value == val then
- return true
- end
- end
- return false
- end
- local function checkValid(name)
- for i = 1, #name do
- chr = string.sub(name,i,i)
- if i > 2 then
- --Get the previous 2 characters
- chrBefore = string.sub(name,i-1,i-1)
- chrBeforeB = string.sub(name,i-2,i-2)
- elseif i > 1 then
- chrBefore = string.sub(name,i-1,i-1)
- chrBeforeB = ""
- else
- chrBefore = ""
- chrBeforeB = ""
- end
- if hasValue(vow, chr) then
- --Its a vowel
- if hasValue(vow, chrBefore) then
- --Two vowels in a row GET OUTTA HERE
- return false
- end
- elseif hasValue(con, chr) then
- --It's a connsonnant
- if hasValue(con, chrBefore) and hasValue(con, chrBeforeB) then
- --Three connsonnants in a row GET OUTTA HERE
- return false
- end
- else
- --It's some weird character GET OUTTA HERE
- return false
- end
- end
- return true
- end
- function mutate(prevName)
- local newName = false
- local ops = {"vow","con"}
- if #prevName > 4 then
- delPoints = {}
- for i = 1, #prevName do
- local possibility = string.sub(prevName,0,i-1) .. string.sub(prevName,i+1,#prevName)
- if checkValid(possibility) then
- table.insert(delPoints, i)
- end
- end
- if #delPoints > 0 then
- table.insert(ops, "del")
- end
- end
- if #prevName < maxLength then
- insPoints = {}
- for i = 1, #prevName+1 do
- local possibility = string.sub(prevName,0,i-1) .. con[1] .. string.sub(prevName,i,#prevName)
- if checkValid(possibility) then
- table.insert(insPoints, {i, "con"})
- end
- local possibility = string.sub(prevName,0,i-1) .. vow[1] .. string.sub(prevName,i,#prevName)
- if checkValid(possibility) then
- table.insert(insPoints, {i, "vow"})
- end
- end
- if #insPoints > 0 then
- table.insert(ops, "ins")
- end
- end
- op = ops[math.random(#ops)]
- if op == "del" then
- local delPoint = delPoints[math.random(#delPoints)]
- --print(tostring(prevName) .. " / " .. tostring(delPoint) .. " / " .. tostring(#prevName))
- newName = string.sub(prevName,0,delPoint-1) .. string.sub(prevName, delPoint+1,#prevName)
- elseif op == "ins" then
- local insPoint = insPoints[math.random(#insPoints)]
- if insPoint[2] == "con" then
- newName = string.sub(prevName,0,insPoint[1]-1) .. con[math.random(#con)] .. string.sub(prevName,insPoint[1],#prevName)
- else
- newName = string.sub(prevName,0,insPoint[1]-1) .. vow[math.random(#vow)] .. string.sub(prevName,insPoint[1],#prevName)
- end
- elseif op == "vow" then
- modPoints = {}
- for i = 1, #prevName do
- if hasValue(vow, string.sub(prevName,i,i)) then
- table.insert(modPoints, i)
- end
- end
- modPoint = modPoints[math.random(#modPoints)]
- curChar = string.sub(prevName,modPoint,modPoint)
- avail = {}
- for k,v in pairs(vow) do
- if v ~= curChar then
- table.insert(avail, v)
- end
- end
- newChar = avail[math.random(#avail)]
- newName = string.sub(prevName,0,modPoint-1) .. newChar .. string.sub(prevName,modPoint+1,#prevName)
- elseif op == "con" then
- modPoints = {}
- for i = 1, #prevName do
- if hasValue(con, string.sub(prevName,i,i)) then
- table.insert(modPoints, i)
- end
- end
- modPoint = modPoints[math.random(#modPoints)]
- curChar = string.sub(prevName,modPoint,modPoint)
- avail = {}
- for k,v in pairs(con) do
- if v ~= curChar then
- table.insert(avail, v)
- end
- end
- newChar = avail[math.random(#avail)]
- newName = string.sub(prevName,0,modPoint-1) .. newChar .. string.sub(prevName,modPoint+1,#prevName)
- end
- return newName
- end
- function create()
- local nameLength = math.random(4,maxLength)
- local name = ""
- local chrBefore = ""
- local chrBeforeB = ""
- for i = 1, nameLength do
- local ops = {}
- if not hasValue(vow, chrBefore) then
- table.insert(ops, "vow")
- end
- if not (hasValue(con, chrBefore) and hasValue(con, chrBeforeB)) then
- table.insert(ops, "con")
- end
- op = ops[math.random(#ops)]
- local chr = ""
- if op == "vow" then
- chr = vow[math.random(#vow)]
- else
- chr = con[math.random(#con)]
- end
- name = name .. chr
- chrBeforeB = chrBefore
- chrBefore = chr
- end
- return name
- end
Advertisement
Add Comment
Please, Sign In to add comment