"Peter Aronson" wrote...


If you want to use sqlite3_randomness to generate a Version 4 UUID according to RFC4122, the following code will can be used:

unsigned char uuid_data[16];

/* We'll generate a version 4 UUID as per RFC4122. Start by generating
128 bits of randomness (we will use 122 of them). */
sqlite3_randomness (16,uuid_data);

/* Set the two most significant bits (bits 6 and 7) of the
clock_seq_hi_and_reserved field to zero and one, respectively. */
uuid_data[8] &= 0x3f;
uuid_data[8] |= 0x80;
/* Set the four most significant bits (bits 12 through 15) of the
time_hi_and_version field to the 4-bit version number from
Section 4.1.3 (which is 4). */
uuid_data[6] &= 0x0f;
uuid_data[6] |= 0x40;

This assumes that sqlite3_randomness generates sufficiently good random numbers, but it appears to in my tests.

Are you saying that sqlite3 does not appear to provide "good random numbers" in your tests, or that it appears to, in your tests?

_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to