UUID libraries generate 32-character UUIDs.
I want to generate 8-character only UUIDs, is it possible?
I do not think that it is possible but you have a good workaround.
new Random(System.currentTimeMillis()).nextInt(99999999);
this will generate random ID up to 8 characters long. generate alphanumeric id:
char[] chars = "abcdefghijklmnopqrstuvwxyzABSDEFGHIJKLMNOPQRSTUVWXYZ1234567890".toCharArray();
Random r = new Random(System.currentTimeMillis());
char[] id = new char[8];
for (int i = 0; i < 8; i++) {
id[i] = chars[r.nextInt(chars.length)];
}
return new String(id);