I like simple and well written C++ libraries, and I’m especially fond of Boost, so I’m going to blog about it some more 🙂

Today I’ll show you how to generate unique IDs using Boost::UUID header only library. There really isn’t much to be said about it other than it’s simple, consists of only few hearer files, and allows you to generate, hash, and serialize unique IDs.

Refer to the documentation for a complete overview. Here’s a sample program that generates and prints a unique ID:

5023e2d9-8008-4142-b1c7-87cda7cb36b3

Program output.

3 Replies to “Generating Unique IDs”

  1. Just be sure you don’t use this way to generate millions of UUIDs in a short time, boost::uuid:s::random_generator constructor is so slooow!
    HINT: maybe re-use the same random_generator instance and just call its operator() in this case.

Leave a Reply