Skip to content

Instantly share code, notes, and snippets.

@medikoo
Created March 16, 2012 18:14
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 medikoo/2051593 to your computer and use it in GitHub Desktop.
Save medikoo/2051593 to your computer and use it in GitHub Desktop.
Proposal for JavaScript GUID
// http://old.nabble.com/Re%3A-UUIDs--p33511279.html
(~~(Math.random() * 1e9)).toString(36) + Date.now()
@piecioshka
Copy link

No trust Math.random...

@medikoo
Copy link
Author

medikoo commented Mar 18, 2012

Yes, this is the reason Date.now is there ;-)

Bulletproof version woud also need to check if given id was not already created and if so, increment result of Date.now

@medikoo
Copy link
Author

medikoo commented Mar 18, 2012

What I'm really using is that: https://github.com/medikoo/es5-ext/blob/master/lib/guid.js
it's good enough

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment