• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Generating unique non-sequential numbers

 
Ranch Hand
Posts: 354
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
  • 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?
 
Abhinav Srivastava
Ranch Hand
Posts: 354
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic