Module:Helixfossilname: Difference between revisions
From A KoL Wiki
m Seed the rng maybe |
m Better lua |
||
Line 5: | Line 5: | ||
local charset = "abcdefghijklmnopqrstuvwxyz()[];:,.!/?-" | local charset = "abcdefghijklmnopqrstuvwxyz()[];:,.!/?-" | ||
local parts = {} | local parts = {} | ||
math.randomseed(os.time() + | math.randomseed(os.time() + math.random(0, 1e6)) | ||
while remaining > 0 do | while remaining > 0 do |
Latest revision as of 07:53, 6 September 2025
Documentation for this module may be created at Module:Helixfossilname/doc
local p = {}
function p.helixfossil(frame)
local remaining = 10
local charset = "abcdefghijklmnopqrstuvwxyz()[];:,.!/?-"
local parts = {}
math.randomseed(os.time() + math.random(0, 1e6))
while remaining > 0 do
local n = math.random(remaining) -- how many repeats of this char
remaining = remaining - n
-- pick one character
local k = math.random(#charset)
local ch = charset:sub(k, k)
-- randomly uppercase (letters only)
if math.random(0, 1) == 0 and ch:match("%a") then
ch = mw.ustring.upper(ch)
end
-- build in chunks, then concat
parts[#parts + 1] = string.rep(ch, n)
end
local s = table.concat(parts)
return mw.html.create("span"):wikitext(s)
end
return p