Hey I was bored so I decided to make this for you:
local module = {}
module.random = function (decimal, array)
print(decimal)
local min = array[1]
local max = array[2]
local finalnum = 0
local finalnum = finalnum + math.random(min, max)
if finalnum ~= max then
for i=1, decimal, 1 do
finalnum = finalnum + (math.random(0,10)/10^i)
print(i)
print(finalnum)
end
end
return finalnum
end
return module
I recommend if you genuinely use this require the id instead so the module updates automatically
local ms = require(7066695577)
print(ms.round(1.48723,2))
Added a random function
What it does (if you havent read in the posts below) it has a second arguement for rounding to decimal places
Heres the code just to prove i rewriten it
function MS.random(x,d) -- math.random but the second parameter is the decimal place (optional)
if type(x) == "table" then
if d == nil then
d = 0
end
local r = 10^d
return math.random(tonumber(x[1])*r,tonumber(x[2])*r)/r
else
return nil
end
end
More info in the original post
Iāve also added an average function
function MS.avg(x) -- gets the average of a table
local sum = 0
for _,v in pairs(x) do
sum = sum + v
end
return sum / #x
end
function MS.random(x, d) -- math.random but the second parameter is the decimal place (optional)
if type(x) ~= "table" then
return nil
end
d = d == nil and 0 or d
local r = 10^d
return math.random(tonumber(x[1]) * r, tonumber(x[2]) * r) / r
end
for average function you can use ... instead of table as parameter
function avg (...)
sum = 0
for i,v in pairs({...}) do
sum += v
end
return sum / #{...}
end
print(avg(1,5,6,23,45,76,5,232,5,76,3,6,45,23,4,45,23,5)) -- giving arguments instead of table of numbers
That does look easier for readability! But Iāll use a practical use for an example, you have a table of all the player stats in the game. And you want the average. I dont think you can use your way in that case. Other than practical uses I think that would be a better idea
This returns the time of a float value from 0-24, for example 15.5 would be 15:30 or 3:30 PM. Seconds support coming soon
local ms = require(game.ReplicatedStorage.MathService)
print(ms.time(13.25)) -- using 1 parameter would give you the 24 hour clock, this'll return "13:15"
print(ms.time(13.25,true)) -- the second parameter is whether or not you want to use the 24 hour system or 12 hour. This'll return "1:15 PM"
Donāt worry since Iāll make up my own code! Furthermore, I asked this so people wouldnāt say, āThere are a lot of other resources out thereā.