Moodul:Rand

Allikas: Vikipeedia

Selle mooduli dokumentatsiooni saab kirjutada asukohta Moodul:Rand/doc.

-- Tagastab ette antud arvuvahemikust juhusliku arvu.
-- Allikas: [[no:Modul:Rand]]

local p = {} 
function p.random(frame)
    local i1, i2 = nil, nil
    if frame.args[2] ~= nil then
    	i1 = tonumber(frame.args[1])
    	i2 = tonumber(frame.args[2])
    elseif frame.args[1] ~= nil then
    	i1 = 1
    	i2 = tonumber(frame.args[1])
    end
    if i1 ~= nil and i2 <= i1 then return i1 end -- Cope with empty intervals
 
    -- math.randomseed(os.time())
    math.randomseed(mw.site.stats.edits + mw.site.stats.pages + os.time() + math.floor(os.clock() * 1000000000))
    if i2 ~= nil then
        return math.random(i1, i2)
    else
        return math.random()
    end
end
return p