Skip to content

Instantly share code, notes, and snippets.

@reqshark
Last active September 29, 2016 02:05
Show Gist options
  • Save reqshark/4e2ba500ab3c253c628e99f3029e4c99 to your computer and use it in GitHub Desktop.
Save reqshark/4e2ba500ab3c253c628e99f3029e4c99 to your computer and use it in GitHub Desktop.
small identifier derived from a single UUID 8 character hex component
console.log( suuid() ); // somethiing like 'e1bdadd6'
function suuid() {
var sm = [], i = 256;
while (i--)
sm[ i ] = ( i < 16 ? '0' : '' ) + ( i ).toString( 16 );
var uu = Math.random() * 0xffffffff | 0;
return sm[ uu & 0xff ] +
sm[ uu >> 8 & 0xff ] +
sm[ uu >> 16 & 0xff ] +
sm[ uu >> 24 & 0xff ];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment