I'm using this one liner to generate a random 18 digit number :
Math.floor(100000000000000000 + Math.random() * 900000000000000000)
The problem is that it always contains one or more zeros at the end, and I don't understand why.
How can I generate a really random number that always contains 18 digits, and without a leading zero?
You have too many digits, you're running against the limit to precision in a javascript number.
It looks like a Problem with the max number Range. You can hack it like this. And it is a better Random number.
Math.floor(10000000000000000 + Math.random() * 90000000000000000)+ "" + Math.floor(Math.random()* 100)
But if you parse to int you have the same problem.
The solution for this so far is to generate two numbers (10 digits + 8 digits) & concatenate them as follow:
Math.floor(1000000000 + Math.random() * 9000000000) + "" + Math.floor(10000000 + Math.random() * 90000000)