Skip to content

Instantly share code, notes, and snippets.

@gabrieldewes
Last active February 3, 2017 20:34
Show Gist options
  • Save gabrieldewes/4d92da6f4f54061f50dabcb0ba07c968 to your computer and use it in GitHub Desktop.
Save gabrieldewes/4d92da6f4f54061f50dabcb0ba07c968 to your computer and use it in GitHub Desktop.
Quickly generate random unique strings
/* It's of unspecified quality and not RFC4122.
* Very slow due to string replaces
*/
var objectId = function () {
var timestamp = (Date.now() / 1000 | 0).toString(16);
return timestamp + 'xxxxxxxxxxxxxxxx'.replace(/[x]/g, function() {
return (Math.random() * 16 | 0).toString(16);
}).toLowerCase();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment