Creating a unique identifier from 3 ints

  • Thread starter Thread starter DaTurk
  • Start date Start date
DaTurk said:
Hi,

I was just curious how you would go about creating a unique identifier
with 3 ints.

What is the range of the three inputs? 32-bit signed?

What is the data type needed for the output? String? Numeric? Size
constraints?
 
DaTurk,

I would treat the three integers as components of a larger, 96 bit
integer. Because there isn't an algorithm for generating higly-unique
96-bit integers (unlike GUIDs, which are 128 bits), I would suggest starting
at 0, and then incrementing by 1 every time you need a new value (across the
96 bits, which you will have to code yourself).
 
For clarification, by 96-bit integer, I mean 96-bit unsigned integer.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Nicholas Paldino said:
DaTurk,

I would treat the three integers as components of a larger, 96 bit
integer. Because there isn't an algorithm for generating higly-unique
96-bit integers (unlike GUIDs, which are 128 bits), I would suggest
starting at 0, and then incrementing by 1 every time you need a new value
(across the 96 bits, which you will have to code yourself).

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

DaTurk said:
Hi,

I was just curious how you would go about creating a unique identifier
with 3 ints.
 
Nicholas Paldino said:
DaTurk,

I would treat the three integers as components of a larger, 96 bit
integer. Because there isn't an algorithm for generating higly-unique
96-bit integers (unlike GUIDs, which are 128 bits), I would suggest
starting at 0, and then incrementing by 1 every time you need a new value
(across the 96 bits, which you will have to code yourself).

Too bad C# doesn't support the obfusc... I mean succinct syntax for handling
carry when incrementing a compound integer:

++num1 || ++num2 || ++num3; // num3 is most significant
 
Hi,

I was just curious how you would go about creating a unique identifier
with 3 ints.

Your question seems a little vague. What are the 3 ints? Just *any*
3 ints? Perhaps a little more about what you are trying to accomplish
will suggest some viable alternatives.

Chris
 
The reason this seems vague is that you don't state whether you need to get
back to the three ints from the unique identifier. If this is the case,
there are several options. If it is not a requirement, then just return an
incrimented static counter.
 
The reason this seems vague is that you don't state whether you need to get
back to the three ints from the unique identifier. If this is the case,
there are several options. If it is not a requirement, then just return an
incrimented static counter.






- Show quoted text -

My apologies. I have three signed integers. 32 bit, c# integers.
They are part of a structure that I'm going to be storing, but it
takes looking at all three of them together to make sure that the
structures are not duplicated. SO I was thinking I could just "or"
them together, or something of the like to create one unique
identifer.

I was thinking you could make all three strings, then append them, end
to end, and then convert them back to an int. But, it could get
bigger then a 64 bit long, which is as big as I want to go.
 
Back
Top