I need to figure out how to code a button that will generate a random 16 digit number every time I push it. I can't find any info on this anywhere.. Any help is appreciated. Thanks.
Printable View
I need to figure out how to code a button that will generate a random 16 digit number every time I push it. I can't find any info on this anywhere.. Any help is appreciated. Thanks.
So a random number from
0 to 8999999999999999 (8 + 15 9's) plus 1000000000000000 (1 + 15 0's)
will give you what you want, right?
So, check out the Random class and it's nextLong() method. Then, before adding 1000000000000000 (actually , make sure that the returned long is smaller than 8999999999999999 (8 + 15 9's) and at least 0 (although you could simply take the abs value and not have to worry about checking for negativity) if not use nextLong again.