As far as I know, there is no way to generate a number, which is random AND globally unique. This way, it would no longer be random. :-)
Chances that two random 6-digit numbers are the same are pretty low indeed.
Let's suppose, you create 1,000 documents. Then the chances you get a duplicate number are 0.1 percent. Am I right? I'm quite puzzled...
Anyway, you may want to use 9-digit random numbers to further diminish that figure.
Do you want to store that number with the current document? I suppose, you can generate a hidden field, where the variable gets stored. But I'm not sure.
Regards,
Steve