• Post Reply Bookmark Topic Watch Topic
  • New Topic
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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Generating unique non-sequential numbers

 
Ranch Hand
Posts: 354
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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: 376
2
Eclipse IDE Firefox Browser Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
UUID ?

https://en.wikipedia.org/wiki/Universally_unique_identifier
 
Abhinav Srivastava
Ranch Hand
Posts: 354
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
Your result would be:
10n1
11n2
12n3
....
99n99

Thus you get 89 distinct, non sequential yet random numbers.
 
reply
    Bookmark Topic Watch Topic
  • New Topic