lundi 14 août 2017

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

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?




Aucun commentaire:

Enregistrer un commentaire