Created
February 15, 2013 23:34
-
-
Save aheadley/4964492 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <time.h> | |
#include <stdint.h> | |
int small_rand() { | |
double d = drand48(); | |
printf("Generated double: %f\n", d); | |
return (int)((uint64_t)d & 0xFFFF); | |
} | |
void print_uuid() { | |
printf("Generated int: %d\n", small_rand()); | |
printf("%04x%04x-%04x-%04x-%04x-%04x%04x%04x\n", | |
small_rand(), small_rand(), | |
small_rand(), | |
small_rand() & 0x0FFF | 0x4000, | |
small_rand() & 0x0FFF | 0x8000, | |
small_rand(), small_rand(), small_rand()); | |
} | |
int main(int argc, char* argv) { | |
int i; | |
srand48(time(0)); | |
printf("%d\n", sizeof(long)); | |
for(i=0; i<10; i++) { | |
print_uuid(); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment