Need to generate a 'unique' ID number?

Need to generate a 'unique' ID number?

Post by Joe Beato » Thu, 05 Dec 1996 04:00:00



I need to know how to generate a unique ID number.  This
number can never be a duplicate of a previous ID number.
Is this possible and if so, does anyone have an example?

Thanks to all who reply...

-Joe-

 
 
 

Need to generate a 'unique' ID number?

Post by Chris Kingsbu » Thu, 05 Dec 1996 04:00:00


: I need to know how to generate a unique ID number.  This
: number can never be a duplicate of a previous ID number.
: Is this possible and if so, does anyone have an example?

This is probably an overkill, but a UUID (Universally Unique
IDentifier) will do this job.  They will guarentee that the ID
will be unique across any internet addressable device.  Unfortunately
they are very large (24 bytes each I think).  One place you can find
the code for UUIds is in the PD version of DCE (do an internet
search for PD-DCE-RPC.tar.gz), but this package contains much more than
you are interested in, and is not very easy to compile.

Hope this helps,
Christopher Kingsbury

 
 
 

Need to generate a 'unique' ID number?

Post by Tim Hollebe » Fri, 06 Dec 1996 04:00:00



> I need to know how to generate a unique ID number.  This
> number can never be a duplicate of a previous ID number.
> Is this possible and if so, does anyone have an example?

Reusing an id is inevitable if the ID has a finite range.
It is trivial to ensure that the maximum amount of time elapses before
this happens.
The simplest solution is to start at zero, and count upwards.

---------------------------------------------------------------------------
Tim Hollebeek         | Disclaimer :=> Everything above is a true statement,
Electron Psychologist |                for sufficiently false values of true.

----------------------| http://wfn-shop.princeton.edu/~tim (NEW! IMPROVED!)

 
 
 

Need to generate a 'unique' ID number?

Post by Peter Sylveste » Fri, 06 Dec 1996 04:00:00



> I need to know how to generate a unique ID number.  This
> number can never be a duplicate of a previous ID number.
> Is this possible and if so, does anyone have an example?

> Thanks to all who reply...

> -Joe-

You can do it with the combination of (2) integer values: the hostid and
either the system time in seconds of a sequence number that you store in
a file.  This assumes you meen network wide unique.  If you just need
local system unique, drop the hostid.
-Peter
 
 
 

Need to generate a 'unique' ID number?

Post by Diego Po » Fri, 06 Dec 1996 04:00:00



> I need to know how to generate a unique ID number.  This
> number can never be a duplicate of a previous ID number.
> Is this possible and if so, does anyone have an example?
> Thanks to all who reply...
> -Joe-

I assume that you need something like the "serial key" in Informix.

What I would suggest is to use a file to store the number, and
write a function that "atomically" reads, increments and writes back
the number every time you invoke it. This activity needs to be
protected by file locks or semaphores.

There is a couple of exceptions that your function has to be able
to handle: empty file and wrap-around back to zero. If you use a
long, you will have plenty of time between wrap-arounds, even in
a very dynamic context. If you need something larger and slower,
look for an arbitrary length math library.

Regarding performance, as always you have the compromise between
reliability (using O_SYNC in open()) and speed (if you don't).

--
Diego Pons

Los Angeles, CA

 
 
 

Need to generate a 'unique' ID number?

Post by Dwight Tov » Thu, 19 Dec 1996 04:00:00


[Posted and mailed]



Quote:> I need to know how to generate a unique ID number.  This
> number can never be a duplicate of a previous ID number.
> Is this possible and if so, does anyone have an example?

> Thanks to all who reply...

> -Joe-

How big a number?  A quick and dirty way would be to just use the time(2)
system call to get the seconds since 1/1/70 and use that as the ID number.
So long as you don't generate more than one a second, this will always
generate a unique number (at least until the timer wraps to zero).

--
Dwight N. Tovey              H&W Computer Systems, Inc.
Software Specialist III      12438 W. Bridger St.  Suite 100


I didn't claw my way to the top of the food chain to eat vegetables!!

 
 
 

1. generating relatively universal unique id

What's a good way to create a relatively universal unique identifier?
I say relatively because the values only have to be unique for all
machines on the same subnet.

I was thinking a 64-bit (unsigned long long) value where the upper
32-bits contained the ip address and lower 32-bits contained the
time. But that'll break if two processes on the same machine ask for a
UID at the same time.

Then I was thinking ip address and pid. But it's possible when the
pid's roll over there will be a duplicate.

Then I thought ip, time, and pid. But that won't fit into 64-bits
(ie. unsigned long long), requires 80-bits. And this breaks if the
same process asks for a UID faster than once per second.

So how about ip, time w/ millisecond resolution, and pid?
Unfortunately something like that would require a structure to hold
the items.

I was hoping I could shove the UID into an atomic type, instead of my
own structure.

Any ideas?

--
Steve

2. Zombie sendmail processes

3. Getting a userid on server side, generating a unique number, etc.

4. i86 Sol2.5: trouble with asy

5. Bad message-ids (was PINE, please don't generate headers)

6. newsgroup display

7. Solaris INN2.4sec2: cant generate message id's

8. How to allocate non cachable driver space?

9. Machine serial number or unique machine id

10. I need an 'md,' but do I need a 'mkdev?'

11. Numbering a text file (UNIX 'number' command)