Is there a way to generate a random UUID, which consists only of numbers?

If you dont want a random number, but an UUID with numbers only use:

String lUUID = String.format("%040d", new BigInteger(UUID.randomUUID().toString().replace("-", ""), 16));

in this case left padded to 40 zeros...

results for:
UUID : b55081fa-9cd1-48c2-95d4-efe2db322a54
in:
UUID : 0241008287272164729465721528295504357972


For the record: UUIDs are in fact 128 bit numbers.

What you see as an alphanumeric string is the representation of that 128 bit number using hexadecimal digits (0..9A..F).

The real solution is to transform the string into it's correspondent 128 bit number. And to store that you'll need two Longs (Long has 64 bit).

Tags:

Java

Random

Uuid