Archived

This topic is now archived and is closed to further replies.

Portable GUID

This topic is 5147 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I need in my application globally unique id, but I assume that MS''s GUID/CoCreateGuid is not very portable code. How to generate portable globally unique id?

Share this post


Link to post
Share on other sites
ok well, a GUID is simply a 32 byte hex string or a 128 bit number. That number can be broken down into 4 dwords, which you can easily use srand to generate a ''unique'' number. I honestly don''t know if there are restrictions as to what numbers you can use when using the GUID, but give it a shot

unsigned long GUID[4]; // GUID
char GUID2[32]; // text string of GUID

Share this post


Link to post
Share on other sites
Hello Kimeli,

Don't use srand at all, you could get the same value on different system depending on how you seed the random and if two system happen to seed with the same value you get same GUID.
Look at what the system can give you as a unique number.
Network card address, cpu id are the two biggest choices.
You should be almost guarantee that the network card MAC address should be unique, and the cpu id should be unique by manufacture at lest.

Try and use both would be a real good one.

Lord Bart


[edited by - lord bart on November 13, 2003 7:44:02 AM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
" How to generate portable globally unique id?"

On UNIX (Linux, AT&T, BSD, Irix, QNX): uuid_gen
On Win32: uuidgen (.NET), guidgen (VC4..6)
On VAX: RPC$UUID_GEN.EXE

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Some source at the bottom of this - complete with the explanation of how to correctly generate them.

http://www.ics.uci.edu/~ejw/authoring/uuid-guid/draft-leach-uuids-guids-01.txt

Share this post


Link to post
Share on other sites
to the first two respondents ... please listen to AP .. the GUID is NOT just any old unique number you think you can generate ... it is a particular algorithm for generating unique 128 bit numbers programatically, you need to use the standard functions (or any function which uses the standard algorithm) ... otherwise your UNIQUE 128 bit number could overlap with the normal UNIQUE 128 bit numbers ... and that would break everything - the existing algorithm absolutely guarantees that codes generated on different machines will be different (assuming that a 48 bit unique network id is available) and also that those generated on the same machine will be unique (assuming no more than 1 guid is generated per time-slice - either 1 second or 1 millisecond i can''t remember) ... but anyone using any other algorithm would violate this guarantee.

Share this post


Link to post
Share on other sites