# Help with math.random()

Hello everyone, I was getting this error where it says “invalid argument #2 to ‘random’ (interval is empty)”. I’ll link the script down below:

``````local Players = game:GetService("Players")
local rand = math.random(1,3720000000)
local charAppearance = Players:GetCharacterAppearanceAsync(rand)

print("User ID: ",rand, " is a lucky person!")
``````

If anyone has any solutions, please lemme know.

I believe the second number is too big for it to calculate.

Oh, how come?

I calculated larger nums like 1e308 with math.random()

I’m not sure… When I tried a number with a few less 0’s it worked

``````local rand = math.random(1,3.72e9)
``````

Fixed it, but doesn’t work

For some reason, If we try using 372e6 it works, But 372e7 doesn’t - By knowing this, We can assume there’s a certain limit for generating random numbers using `math.random`. Maybe you could try using `Random.new():NextInteger()` instead?

``````-- Works
local RandomOne = math.random(1, 372e6)
print(RandomOne)

-- Errors
local RandomTwo = math.random(1, 372e7)
print(RandomTwo)
``````

I get your point, but I believe there were a much, much greater limit than 3.72e9

There’s indeed a much bigger limit. I did a research and i found out that this is an “issue” with math random itself. (Can be found at this post)

As i mentioned above, You should use the Random Object instead, Since it doesn’t has this problem and also comes with some extra methods related to number-generation.

I did a bit of testing, and the limit for `Random:NextNumber` is somewhere between 2^1023 and 2^1024, which I assume is a floating point limit thing. For `Random:NextInteger`, it starts returning negative values for 2^63, which I assume is an integer overflow thing.

Yeah, or I can just make my own random func

Yeah, so I used this line of code:

``````local random = Random.new(tick()):NextInteger(1,3.72e9)
``````

And I believe it has a much higher limit.