
Make sure to compile with -luuid so that the linker knows that uuid_generate_random() and uuid_unparse() are defined in libuuid.

Uuid_unparse() doesn't allocate it's own memory to avoid a segmentation fault upon execution you must do that with manually with uuid = malloc(37) (you can also store the UUID in a char array of that length: char uuid ). Equivalent of printf("%s\n", uuid) - just my personal preference * whose case depends on the system's locale. * Produces a UUID string at uuid consisting of letters * Produces a UUID string at uuid consisting of lower-case letters. * Produces a UUID string at uuid consisting of capital letters. 37 is the length of a UUID (36 characters), plus '\0'.
C UUID GENERATOR FULL
It is likely more performant and can take full advantage of the OS APIs. If you can easily access the UUID functionality in another library, use it. From there it is as simple calling it for each of the 5 parts of a UUID by their respective lengths. * uuid_unparse() doesn't allocate memory for itself, so do that with These two functions allow you to generate hex random characters of n length.

* binuuid to get a usable 36-character string. * for the UUID generated is in binary format * in the 'unparsed' UUID will depend on your system's locale). * Don't uncomment either if you don't care (the case of the letters * Uncomment to always generate lower-case UUIDs.

* Uncomment to always generate capital UUIDs. * For uuid_generate() and uuid_unparse() */ This is a simple program that generates an entropy-based (random) UUID and writes it to stdout, then exits with status 0. The uuid will be generated based on high-quality randomness from /dev/urandom. (Packages libuuid1 and uuid-dev on Debian.) The uuidgenerate function creates a new universally unique identifier (UUID). This functionality is provided by libuuid.
