Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • 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
  • 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
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: 369
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.
 
You would be much easier to understand if you took that bucket off of your head. And that goes for the tiny ad too!
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic