..:D&G:.. Posted May 8, 2015 Share Posted May 8, 2015 Hello guys, I am making a login system and I want to generate a random salt from some numbers using math.random local salt = math.random(106060023000, 9919995299949969) The problem is that I get a negative number like -29404583 Any ideas? Thanks Link to comment
WhoAmI Posted May 8, 2015 Share Posted May 8, 2015 Maybe replace it to random string? http://lua-users.org/wiki/RandomStrings Link to comment
TAPL Posted May 8, 2015 Share Posted May 8, 2015 You can use math.abs to make it positive number. Link to comment
rtx Posted May 8, 2015 Share Posted May 8, 2015 You can only pass 2^31-1 bit integer arguments in the math class. This means the maximum number you can represent is: 2147483647 You're getting a negative value because you're getting an integer overflow, meaning the value you're trying to represent is higher than the value I've just mentioned and therefore the bit signal is affected. The solution for your problem is simple (assuming you really need a number that high): local a = "" for k = 1, 12 do a = a .. tostring(math.random(0,9)) end Link to comment
Walid Posted May 8, 2015 Share Posted May 8, 2015 as TAPL said try to use math.abs. local salt = math.random(106060023000, 9919995299949969) local salt2 = math.abs(tonumber(salt)) Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now