I work for a banking project and their requirement is to generate unique transaction reference for each transaction. The format for UTR is:
<BankCode><YYDDD><5 digit SequenceId>.
This 5 digit sequence ID can be alphanumeric as well. The transaction count each day can go up to 100-200K.
If I use an Oracle sequence then I can have only 10K values.
I tried to use SecureRandom
generator and generated 200K 5 length string but it generated around 30 duplicate strings.
Below is the code snippet I used
int leftLimit = 48;
int rightLimit = 122;
int i1=0;
Random random = new SecureRandom();
while (i1<200000) {
String generatedString = random.ints(leftLimit, rightLimit+1)
.filter(i -> (i<=57||i>=65) && ( i<=90|| i>=97))
.limit(5)
.collect(StringBuilder::new,
StringBuilder::appendCodePoint,
StringBuilder::append)
.toString();
System.out.println(generatedString);
i1++;
}