Skip to content

Instantly share code, notes, and snippets.

@aheadley
Created February 15, 2013 23:34
Show Gist options
  • Save aheadley/4964492 to your computer and use it in GitHub Desktop.
Save aheadley/4964492 to your computer and use it in GitHub Desktop.
#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