-1

I had a requirement to generate guid in C, How can generate guid(http://en.wikipedia.org/wiki/Globally_unique_identifier) in libc . I need to generate guids randomly .

Kajal
  • 223
  • 4
  • 15
  • What is confusing about the specification on wikipedia? `libc` has a `random()` function which generates anything from 0 to MAXINT. You can use it to generate random bytes by modulating it by the max size of a byte, or even dividing. This won't guarantee particularly good randomness but sufficient for anything not-too-sensitive. Once you have the bytes, you just follow the spec in wikipedia – rliu Apr 19 '13 at 02:15
  • @roliu can it guaranteed uniqueness all over – Kajal Apr 19 '13 at 02:18
  • 2
    http://linux.die.net/man/3/libuuid ? – Duck Apr 19 '13 at 02:19

1 Answers1

2

Cont: Ref : http://linux.die.net/man/3/uuid_generate

uuid_generate_time_safe - create a new unique UUID value Synopsis

#include <uuid/uuid.h>
void uuid_generate(uuid_t out);void uuid_generate_random(uuid_t out);void
uuid_generate_time(uuid_t out);int uuid_generate_time_safe(uuid_t out);
Description

The uuid_generate function creates a new universally unique identifier (UUID). The uuid will be generated based on high-quality randomness from /dev/urandom, if available. If it is not available, then uuid_generate will use an alternative algorithm which uses the current time, the local ethernet MAC address (if available), and random data generated using a pseudo-random generator. The uuid_generate_random function forces the use of the all-random UUID format, even if a high-quality random number generator (i.e., /dev/urandom) is not available, in which case a pseudo-random generator will be substituted. Note that the use of a pseudo-random generator may compromise the uniqueness of UUIDs generated in this fashion.

Kajal
  • 223
  • 4
  • 15