UUID gives 128 bits, where the range of 10 digits is about 33 bits, using 210 is approx. 103. So the uniqueness is reduced.
One can do something like:
String randomCode() {
UUID uuid = UUID.randomUUID();
long lo = uuid.getLeastSignificantBits();
long hi = uuid.getMostSignificantBits();
lo = (lo >> (64 - 31)) ^ lo;
hi = (hi >> (64 - 31)) ^ hi;
String s = String.format("%010d", Math.abs(hi) + Math.abs(lo));
return s.substring(s.length() - 10);
}
This folds the 128 bits almost 4 fold to deliver 10 digits.
That is as said not necessarily unique.
It might be better to use a secret pseudo-random sequence, requiring saving a state. Or any of the other random generators / System.nanos().