Skip to content

Instantly share code, notes, and snippets.

@shabinesh
Created April 17, 2012 03:57
Show Gist options
  • Save shabinesh/2403356 to your computer and use it in GitHub Desktop.
Save shabinesh/2403356 to your computer and use it in GitHub Desktop.
unique id generator
#include<stdio.h>
#include<sys/time.h>
int main()
{
int i;
for(i =0;i < 32; i++)
func(i);
return 0;
}
int func(unsigned long u_id)
{
struct timeval t;
unsigned long id;
gettimeofday(&t,NULL);
id = (t.tv_sec * 1000 * 1000) + (t.tv_usec * 1000) << 42;
id |= (u_id % 16777216) << 24;
printf("%lu\n ",id);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment