This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
thegreatstudio's profile picture

How to make a string generator?

Started by thegreatstudio, 14 May 2013 - 11:05 AM
thegreatstudio #1
Posted 14 May 2013 - 01:05 PM
hello guys i have a question that how to make a string generator. Like in video games.
Lyqyd #2
Posted 14 May 2013 - 02:35 PM
You're going to have to provide a lot more detail than that.
H4X0RZ #3
Posted 14 May 2013 - 05:00 PM
This function is generating strings :

function stringGen(lenght)
parts = {"a", "b", "c", "d"} --you can add more

function genNumb()
return math.random(1, #parts)
end

output = {}

for u = 1, lenght do
table.insert(output, parts[genNumb()])
end

return table.concat(output)
end

I don't know f it works, but trying is the best way to learn :P/>
BlankTitle #4
Posted 14 May 2013 - 06:59 PM
Do you mean like the code string or the item string?
You need to tell us if you want help.
KaoS #5
Posted 15 May 2013 - 03:09 AM

local function generate(len)
  local str=""
  for i=1,tonumber(len) or 1 do
    str=str..string.char(math.random(33, 126))
  end
  return str
end