The editors' meeting has been canceled for technical reasons.

Module:RandomText

From NeuroWiki
Revision as of 03:20, 24 January 2025 by Selfice (talk | contribs) (Created page with "-- Module:RandomText local p = {} -- Function to randomly select one of the provided arguments function p.choose(frame) -- Get all the arguments passed to the template local args = frame.args -- Collect all non-nil, non-empty arguments local options = {} for _, value in ipairs(args) do if value and value ~= "" then table.insert(options, value) end end -- If there are no valid arguments, return empty if #optio...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Documentation for this module may be created at Module:RandomText/doc

-- Module:RandomText
local p = {}

-- Function to randomly select one of the provided arguments
function p.choose(frame)
    -- Get all the arguments passed to the template
    local args = frame.args

    -- Collect all non-nil, non-empty arguments
    local options = {}
    for _, value in ipairs(args) do
        if value and value ~= "" then
            table.insert(options, value)
        end
    end

    -- If there are no valid arguments, return empty
    if #options == 0 then
        return ""
    end

    -- Randomly choose one of the options
    math.randomseed(os.time()) -- Seed the random number generator
    local choice = math.random(1, #options)

    return options[choice]
end

return p