Jump to content

[HELP] Random number problem


Recommended Posts

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...