Is it possible to create a unique/random 8 digit number with a script?

I need a script that can create random 8 digit numbers. But I have no idea how can I write one.
I thought mathrandom could help me at the moment but I couldn’t figure out how I can Implement it into a script like this.

2 Likes

Use 10000000 and 99999999, together they will give a random number of 8 digits

local N = math.random(10000000, 99999999)
print(N, tostring(N):len())	     -- random number - length of number
1 Like
local rand = math.random(0, 99999999)
local randLen = string.len(tostring(rand))
if randLen < 8 then
	rand = string.rep("0", 8 - tonumber(randLen))..rand
end

print(rand)

Slight improvement, this will generate 8 digit numbers with leading 0’s.

2 Likes

Thank you this should work better than the other one.