The
Java 5 UUID is essentially a 122-bit random number, compared to Math.random() which is a 53-bit random number, so collisions are only much less likely with a UUID, not impossible.
That said, you could generate a 128-bit random number like this:
If you want to avoid collisions altogether, you'll have to
test for them before returning the number.