Jump to content

Module:Math

Wikipedia se
Badlao 05:25, 21 Farwari 2013 tak imported>Banaticus (created random module) se
(farka) ← Purana badlao | Abhi ke badlao (farka) | Nawaa badlao→ (farka)

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

local mathy = {}

function mathy.random( frame )
    first = tonumber(frame.args[1]) -- if it doesn't exist it's NaN, if not a number it's nil
    second = tonumber(frame.args[2])

    if first then -- if NaN or nil, will skip down to final return
        if first <= second then -- could match if both nil, but already checked that first is a number in last line
            return math.random(first, second)
        end
        return math.random(first)
    end   
    return math.random()
end