模組:Rand

Wikipedia (chū-iû ê pek-kho-choân-su) beh kā lí kóng...

可在模組:Rand/doc建立此模組的說明文件

local func = {}

function func.randitem( frame )
    local text = frame.args[1]
    local list = mw.text.split(text, frame.args[2] or '[\n\r]%s*%*%s*')
    
    math.randomseed(os.time())
    
    local n = #list
    local r = 0

    if mw.text.trim(list[1]) == '' then
    	r = math.random(n - 1) + 1
    else
    	r = math.random(n)
    end
    
    return mw.text.trim(list[r])
end

return func