[Qt-interest] QUuid with QUuid::Time

Konrad Rosenbaum konrad at silmor.de
Mon Jun 14 15:41:15 CEST 2010


On Mon, June 14, 2010 12:51, metin d wrote:
> Documentation says that QUuid::createUuid () creates an UUID using
> QUuid::Random. On the other hand, I want to get UUID's by using
> QUuid::Time, because I want to get UUIDs which are exactly unique. Do you
> have any suggestion?

Why do people keep pretending that a 128 bit value with about a dozen
fixed bits could come anywhere close to "unique"? Sigh.

Time based UUIDs are no more unique than random based, or MAC based UUIDs.
The probability of a collision varies between one in 2^32 and one in 2^48
(or something thereabouts, some bits are missing because they are fixed
and implementations vary).

With the algorithms given and the width of the value you don't get
anything better. The correct name for this thing would be QLUID - quite
likely unique ID, but UUID with the first "U" being translated as
"universally" was better marketing... ;-)

So:

If you want a value that is unique inside the one instance of the program
that is running - use a counter! It is computationally cheaper and safer
against collisions.

If you want something that is probably unique and works across several
instances, including instances running on different machines: use UUID and
be prepared to fail gracefully in case of a collision (which will happen
once per blue moon if you use a LOT of UUIDs or even never if you need
only the occasional one).

If you need something that is absolutely unique: use a central registry.

If you need something that is cryptographically secure: forget UUIDs, they
are quite guessable. Use proper certificates and public key crypto.


    Konrad




More information about the Qt-interest-old mailing list