Why does math.random(999999999999) returns 1 in Lua?

Viewed 326

I just tried: print(math.random(999999999999)) and it has printed 1.

Also any math.random() that includes 999999999999 is printing the same thing. Some examples:

print(math.random(1.999999999999)) » 1

print(math.random(1999999999999)) » 1

for k,v in next,{math.random(999999999999), math.random(1999999999999), math.random(2.999999999999)} do
    print(v)
end

» 1

local n = math.random(999999999999)
print(n==1)

» true

Then I think you understood (if you know Lua of course). Can you explain me?

@Edits:

The Lua version I'm using is 5.2.

I also tried print(math.random(-999999999999)) and it printed 111711452. It looks like it worked as a positive number.

1 Answers
Related