Created
March 16, 2012 18:14
-
-
Save medikoo/2051593 to your computer and use it in GitHub Desktop.
Proposal for JavaScript GUID
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://old.nabble.com/Re%3A-UUIDs--p33511279.html | |
(~~(Math.random() * 1e9)).toString(36) + Date.now() |
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
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
No trust Math.random...