Skip to content

Instantly share code, notes, and snippets.

@serenitii
Created January 5, 2018 03:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save serenitii/d51078ca7aa7bfdd5d508fbf2d15ec4b to your computer and use it in GitHub Desktop.
Save serenitii/d51078ca7aa7bfdd5d508fbf2d15ec4b to your computer and use it in GitHub Desktop.
32bit GUID Generator
static u32 guid_32bit() {
static u32 s_guid_step_counter = 0;
struct timeval curr_time;
gettimeofday(&curr_time, nullptr);
//printf("%ld:%ld\n", curr_time.tv_sec, curr_time.tv_usec);
u32 secs = curr_time.tv_sec % 1000000;
u32 msecs = curr_time.tv_usec / 1000;
auto val = secs * 1000 + msecs + ++s_guid_step_counter;
return val;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment