I'm trying to generate a unique id for each request in a DS. I'm thinking of concatenating a random integer and timestamp of the request's receipt. Since, getting a random integer can result in negative values I decided to print hex representation:
String randomPrefix = Integer.toHexString(RANDOM.nextInt()).toUpperCase();
java.util.Date date = new java.util.Date();
String timestamp = Long.toHexString(date.getTime()).toUpperCase();
String id = randomPrefix.concat(timestamp);
I'm nt very good at probabilities, but I want to know if there are other operations which could result in equally low (or even better chances of not seeing repetition) in this value with shorter string lengths.
Speaking like a layman, concatenation should X the chances of recurrence whereas addition would + it (which has higher chances of being repeated).
Please suggest other ways to result in a cleaner and shorter ID (or confirm if this is correct).
P.S: Please forgive me for the layman language, working on it. :(