Pergunta

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 .

Foi útil?

Solução

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top