Module:Maths
Apparence
Ce module permet d'utiliser des fonctions mathématiques, il est inclut dans d'autres modules.
local p = {}
-- numHasard([[[borneMinInc], borneMaxInc]. nbChiffres])
function p.numHasard(frame)
math.randomseed(os.time())
if frame.args[1] and frame.args[2] then
if frame.args[3] then
return string.sub(tostring(math.random(frame.args[1], frame.args[2]) + math.pow(10, frame.args[3])), -1 * frame.args[3])
else
return math.random(frame.args[1], frame.args[2])
end
elseif frame.args[1] then
return math.random(frame.args[1])
else
return math.random()
end
end
-- numPokemon()
function p.numPokemon(frame)
math.randomseed(os.time())
return string.sub(tostring(math.random(1, 1025) + 10000), -4)
end
-- PGCD et PPCM, de https://rosettacode.org/wiki/Least_common_multiple#Lua
function p.gcd( m, n )
while n ~= 0 do
local q = m
m = n
n = q % n
end
return m
end
function p.lcm( m, n )
return ( m ~= 0 and n ~= 0 ) and m * n / p.gcd( m, n ) or 0
end
return p