Win a copy of The Career Toolkit this week in the Jobs Discussion 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Paul Clapham
• Ron McLeod
• Bear Bibeault
• Liutauras Vilda
Sheriffs:
• Jeanne Boyarsky
• Tim Cooke
• Junilu Lacar
Saloon Keepers:
• Tim Moores
• Tim Holloway
• Stephan van Hulst
• Jj Roberts
• Carey Brown
Bartenders:
• salvin francis
• Frits Walraven
• Piet Souris

# Unique number generation

Greenhorn
Posts: 2
i want to generate a unique random number.
But the constraint is this number must not be repeated in 10 months span.
it should be unique and itz length must be 9 digits long.

Sheriff
Posts: 7023
Welcome to JavaRanch, kasi!
In 10 months time, about how many ids are to be generated?

Ranch Hand
Posts: 1873
HI kasi
As Dirk pointed out, it would more helpful to know "how many IDs you need to generate" BUT here is some rough logic I can think of right now,
If we have 9 digit number to be generated that should not be repeated in 10 months span then I would suggest something like following,
- Consider positions of digits from 0 to 8, left-to-right (total 9 digits).
- First digit (0th) you can use to indicate the month number,
0 for 1st month
1 for 2nd month
2 for 3rd month etc...
- Second two digits (1st and 2nd) to indicate the day in the month (00 to 31)
- For remaining 6 digits (3rd to 8th position) you can generate random number.
This way atleast we would ensure that in a single day in any month we can generate 10^6 random numbers and we reduce our scope of "having uniqueness" to 10^6 then 10^9.
Now, this would not be really fully random as you would know the first 3 numbers always but I am just throwing ideas from top of my head if they are useful in anyway...
I wish I was a mathemetician
Regards
Maulin

 His brain is the size of a cherry pit! About the size of this ad: the value of filler advertising in 2020 https://coderanch.com/t/730886/filler-advertising