45 lines
1.1 KiB
Lua
45 lines
1.1 KiB
Lua
|
local rng = {}
|
||
|
function rng.markup() return math.random() > 0.5 and "plain" or "imageboard" end
|
||
|
function rng.generate_str(length,characters)
|
||
|
return function()
|
||
|
local t = {}
|
||
|
local rnglength = math.random(2,length)
|
||
|
for i = 1,rnglength do
|
||
|
local rngpos = math.random(#characters)
|
||
|
local rngchar = string.sub(characters,rngpos,rngpos)
|
||
|
table.insert(t,rngchar)
|
||
|
end
|
||
|
local ret = table.concat(t)
|
||
|
return ret
|
||
|
end
|
||
|
end
|
||
|
function rng.characters(mask)
|
||
|
local t = {}
|
||
|
for i = 1,255 do
|
||
|
if string.match(string.char(i), mask) then
|
||
|
table.insert(t,string.char(i))
|
||
|
end
|
||
|
end
|
||
|
return table.concat(t)
|
||
|
end
|
||
|
function rng.maybe(input,chance)
|
||
|
chance = chance or 0.5
|
||
|
if math.random() < chance then
|
||
|
return input
|
||
|
end
|
||
|
end
|
||
|
rng.any = rng.generate_str(1024,rng.characters("."))
|
||
|
rng.subdomain = rng.generate_str(30,rng.characters("[0-9a-z]"))
|
||
|
rng.storyname = rng.generate_str(10,"[a-zA-Z0-9$+!*'(),-]")
|
||
|
rng.storyid = function() return tostring(math.random(1,10)) end
|
||
|
rng.tags = function()
|
||
|
local tag_gen = rng.generate_str(10,"[%w%d ]")
|
||
|
local t = {}
|
||
|
for i = 1,10 do
|
||
|
table.insert(t,tag_gen())
|
||
|
end
|
||
|
return table.concat(t,";")
|
||
|
end
|
||
|
|
||
|
return rng
|