Generate fixed length unique number

  • Thread starter Thread starter David Dvali
  • Start date Start date
D

David Dvali

Hello.

How can I generate some fixed length unique number (for example 6 character)
based on some number like 1, 2, .. 45, 46, 47 (Generally I will use unique
ID of the database record as base number)?

Thank you.
 
David Dvali said:
How can I generate some fixed length unique number (for example 6 character)
based on some number like 1, 2, .. 45, 46, 47 (Generally I will use unique
ID of the database record as base number)?

What's the scope of the required uniqueness? If you're limited to 6
digits, you're not going to be able to generate more than a million of
them, for instance...
 
Yes I know. I don't need more.

Jon Skeet said:
What's the scope of the required uniqueness? If you're limited to 6
digits, you're not going to be able to generate more than a million of
them, for instance...
 
David Dvali said:
Yes I know. I don't need more.

Could you be a bit clearer? What's your actual situation? Why can't you
just use the unique ID of the database record as the number itself?
 
I was thinking the same. Just left pad the number with zeros if for some
reason you needed a total of 6 digits for formatting or something.
 
Back
Top