Skip to content

Instantly share code, notes, and snippets.

@ah-cog
Forked from shabinesh/id.c
Last active May 7, 2016 22:49
Show Gist options
  • Save ah-cog/7c7adae60c0d0ccf717effece80072a9 to your computer and use it in GitHub Desktop.
Save ah-cog/7c7adae60c0d0ccf717effece80072a9 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