Numbers break at 32 bits

  1. What do you want to achieve?

I want to know why I am unable to use numbers over 32 bits without it breaking.

  1. What is the issue?

I have been using very large numbers recently(in hexadecimal) for a private project. I have used it in a math.random function which looked something like this:


When I try that, my output was:

):1: invalid argument #2 to 'random' (interval is empty)

I looked up the error on the devforum, and all I found was that you get the error when the second number is 0 or something. So I tried to swap the numbers around and I got the number -2147483648. And I had ran it again and it hadn’t changed, no matter how many times it would be the same number. So that kind of solved why math.random was erroring but it still didn’t explain why it was a negative number. I got rid of some of the digits and I found that it breaks at 32 bits. I haven’t found any post documenting this. I would’ve reported this on bug reports if I was able to but unfortunately I can’t as I am not a regular and I am pretty sure I can’t become a regular at the moment. I would like it if someone could help explain why this is not working.

math.random casts the value of the argument to 32-bit integer, and the process depends on the implementation of Luau, what Luau is compiled in, and the platform.
I believe any floats outside of the 32 bit integer range [-2^32, 2^32) will be casted to -232 (-2147483648) on x86-64 machines in C and C++ therefore Lua(u) as Lua(u) is compiled with C++ on Roblox.


Would there be any way to fix this?

make your own number system or randomize things in smaller parts. If you could show us your system or tell us why you need to do many random options that could help.

1 Like