Win a copy of Microservices Testing (Live Project) this week in the Spring forum!
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Tim Cooke
• Ron McLeod
• Jeanne Boyarsky
• Paul Clapham
Sheriffs:
• Liutauras Vilda
• Henry Wong
• Devaka Cooray
Saloon Keepers:
• Tim Moores
• Stephan van Hulst
• Tim Holloway
• Al Hobbs
• Carey Brown
Bartenders:
• Piet Souris
• Mikalai Zaikin
• Himai Minh

# Generating unique non-sequential numbers

Ranch Hand
Posts: 354
• Number of slices to send:
Optional 'thank-you' note:
Been scratching my head over this. I am trying to find a way to generate a

1. Number having a fixed length (no of digits)
2. Unique but not easily guessable (that rules out things like DB generated seq numbers).

It seems like a some sort of bijection function would foot the bill.

Thoughts?

Ranch Hand
Posts: 371
2
• 1
• Number of slices to send:
Optional 'thank-you' note:

Abhinav Srivastava
Ranch Hand
Posts: 354
• Number of slices to send:
Optional 'thank-you' note:
UUID's are not very user friendly. Consider something like a SSN or a Bank Acct#. (I guess they are not truly random but just for example's sake)...

Ranch Hand
Posts: 62
• Number of slices to send:
Optional 'thank-you' note:
so you have a known number of digits, be that N. Just use the first 2 out of that N digits as an increment, then the rest N-2 digits are random.

For example you want to generate 89 random numbers of 6 digits, then you generate 89 numbers of 4 digits be those n1, n2, .., n99.