Module:Random: Difference between revisions

Content deleted Content added
try to make the functions available more reliably
rework the number function
Line 60:
 
function p._number(args)
-- Returns a random number. This algorithm is taken from [[Module:Math]].
first = tonumber(args[1]) -- if it doesn't exist it's NaN, if not a number it's nil
second = tonumber(args[2])
-- This needs to use if statements as math.random won't accept explicit nil values as arguments.
if first then -- if NaN or nil, will skip down to final return
if first then
if first <= second then -- could match if both nil, but already checked that first is a number in last line
if second and first <= second then -- Second number cannot be less than the first, or it causes an error.
return math.random(first, second)
else
return math.random(first)
end
else
return math.random(first)
return math.random()
end
return math.random()
end