212 posts
Location
Somewhere in this dimension... I think.
Posted 21 February 2016 - 01:50 AM
Why does math.random return "Empty interval?" It seems to do it with really large numbers. However
2^31 < 10^11
>True
math.random(10^11)
>SomeRandomValue
math.random(2^31)
>bad argument #1: interval is empty
So what EXACTLY are the limitations (and why can I not use 2^127 even though it isn't considered inf or infinity?)
–Edit–
I should probably mention that 2^128 is considered "infinity" but math can still be performed on it, so theoretically math.random(2^128) should work just as well.
Edited on 21 February 2016 - 01:12 AM
957 posts
Location
Web Development
Posted 21 February 2016 - 02:11 AM
This unexpected behavior (bug?) is due to how math.random treats the input arguments passed in Lua 5.1 from lmathlib.c
Source:
http://stackoverflow.com/questions/20171224/interval-is-empty-lua-math-random-isnt-working-for-large-numbers
212 posts
Location
Somewhere in this dimension... I think.
Posted 21 February 2016 - 02:17 AM
This unexpected behavior (bug?) is due to how math.random treats the input arguments passed in Lua 5.1 from lmathlib.c
Source:
http://stackoverflow...r-large-numbers
I'm using Lua 5.2 (CC 1.78 (CC was never upgraded to Lua 5.2 apparently? Just a small portion was added?) , which that post claims fixes the bug, and 10^11 should break it as well according to the post.
Plus further down the thread someone notes that 2^31 should work even in Lua 5 Tried with a Lua 1.54 interpreter installed awhile ago and 2^31 returned empty.
Edited on 21 February 2016 - 01:23 AM
957 posts
Location
Web Development
Posted 21 February 2016 - 02:24 AM
I'm using Lua 5.2 (CC 1.78), which that post claims fixes the bug
Just out of curiosity, does disabling Lua 5.1 features in the config fix it?
I doubt it will but you never know.
I have to wonder why you want a random number that big.
212 posts
Location
Somewhere in this dimension... I think.
Posted 21 February 2016 - 02:33 AM
I don't actually want a number 2^31 sized. I want a number 2^256 sized but I figure "Infinity" is probably a bad thing to try and get around. Disabling 5.1 functions had no effect even though Lua 5.2 fixed it. Suggesting ComputerCraft has yet to update. (or LuaJ)
Edited on 21 February 2016 - 01:45 AM
756 posts
Posted 21 February 2016 - 05:20 AM
I don't actually want a number 2^31 sized. I want a number 2^256 sized but I figure "Infinity" is probably a bad thing to try and get around. Disabling 5.1 functions had no effect even though Lua 5.2 fixed it. Suggesting ComputerCraft has yet to update. (or LuaJ)
What are you using a 2^256 large number for?
2^256 makes me think it's some kind of cryptographic key for a 256bit cipher, if that's the case there is a better way to store it by having a table with 32 random numbers between 0 and 2^8.
If it's not about crypto then I would still suggest the above method, or a similar one with a table containing 8 random numbers between 0 and 2^32, but there's just no way of storing a 2^256 number in a Lua number format.
Edited on 21 February 2016 - 06:01 PM
7083 posts
Location
Tasmania (AU)
Posted 21 February 2016 - 07:57 AM
Just out of curiosity, does disabling Lua 5.1 features in the config fix it?
That removes easy access to a few functions, but doesn't actually change the version of Lua that's included in the CC mod archive (which is, of course, still 5.1).
957 posts
Location
Web Development
Posted 21 February 2016 - 06:54 PM
Just out of curiosity, does disabling Lua 5.1 features in the config fix it?
That removes easy access to a few functions, but doesn't actually change the version of Lua that's included in the CC mod archive (which is, of course, still 5.1).
I figured as much. Worth I try I guess.