Math.random() Erroring (interval is empty) with large numbers?

I recently ran into a rather odd problem that seems to have to do with using math.random() using large numbers. When calling math.random() with 2 decently large numbers (roughly 1.9 and 2.1 billion), I get the error “1: invalid argument #2 to ‘random’ (interval is empty)”. I know this is typically caused by calling it with an invalid range, however that isn’t the problem here.

I confirmed this by a simple print statement in the command bar using the two numbers my code supplies which also for some peculiar reason errors as shown below. I’ve seen nothing about math.random failing with larger numbers even far exceeding the billions, however here it is. Has anyone else encountered this and any ideas on a different way of going about it?

I tried running the code in the command. Doesn’t seem to work for me either. Got the same result as yours.

1 Like

This is a documented “issue” use “Random.new()” instead.

2 Likes

Thanks, I’ll use Random instead. I couldn’t find any mention of the upper limit despite my searches for some reason (even on just lua documentations of the math functions) but upon testing a bit more I realized it was the 32 bit integer limit. Glad Random willl work instead.

Is it a 32 bit integer limit on the arguments themselves or the difference between the 2 arguments?

Seems to be the arguments itself. math.random(x, 2147483647) works fine but anything above it errors with interval is empty.

That’s a very elusive error message as well.

1 Like