I have tried UUID and its generating 32 character string.But I want 16 character unique string
I have tried UUID and its generating 32 character string.But I want 16 character unique string
Another best option by using Apache commons
import org.apache.commons.lang3.RandomStringUtils;
RandomStringUtils.randomAlphanumeric(10);
above code will generate a random string. output: ZBgTxJX93f
Reference : https://www.mkyong.com/java/java-how-to-generate-a-random-string/
A GUID / UUID is a 128 bit number often represented as a series of 32 HEX values. A HEX value is base 16. If you want to represent the same 128bit value in 16 digits then you'll need to use base 64 digits.
To do that you'll need to create a mapping similar to how HEX values are mapped. The English alphabet has 26 characters and ASCII has a value for them in both upper and lower case. This gives us 52 distinct digits. Add to that the numerical values 0 to 9 and that brings us to 62. Then you can pick whatever to get you to 64, say '*' and '+', or whatever makes the most sense taking into account their position in the ASCII table. So then you'd create a lookup table that translates between these 64 digits to build a 128 bit value.
This should give you a full 128bit value represented in 16 Base-64 characters. It would look something like: GaUvr*olp42xgtyu
Note that this is not standard and you'd need to control both the encoder and decoder.