 # Need help with my script

``````function rand(min, max)
return math.random()*max+1--this is needed because I need it to be min or bigger
end

while true do
local a = rand(1, 3)
print(a)
end
``````

The problem is that it also prints number that is bigger than 3
I want it to print random number(don’t need to be integer) between 1 and 3

1 Like

Not sure what you are trying to do but you can do this instead…

``````while true do
local a = math.random(1, 3)
print(a)
end
``````

If you’re trying to make another math.random() system without the 2 arguments.

``````local function rand(min, max)
return math.random() * (max - min) + min
end

while true do
local a = rand(1, 3)
print(a)
end
``````

To get rid of the decimals you can use math.floor or math.ceil.

``````local function rand(min, max)
return math.floor(math.random() * (max - min) + min)
end

while true do
local a = rand(1, 3)
print(a)
end
`````````
3 Likes

This is the solution

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.