Win a copy of TDD for a Shopping Website LiveProject this week in the Testing 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
• Paul Clapham
• Ron McLeod
• Jeanne Boyarsky
• Tim Cooke
Sheriffs:
• Liutauras Vilda
• paul wheaton
• Henry Wong
Saloon Keepers:
• Tim Moores
• Tim Holloway
• Stephan van Hulst
• Carey Brown
• Frits Walraven
Bartenders:
• Piet Souris
• 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: 369
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.