Created
February 5, 2015 21:36
-
-
Save dacur/48b2cc626bb35fece6ea to your computer and use it in GitHub Desktop.
Create a unique GUID. I sometimes use these when I need a unique value; for instance, when I need to add a unique ID to a DIV.
This file contains hidden or 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
| function CreateGuid() { | |
| function _p8(s) { | |
| var p = (Math.random().toString(16) + "000000000").substr(2, 8); | |
| return s ? "-" + p.substr(0, 4) + "-" + p.substr(4, 4) : p; | |
| } | |
| return _p8() + _p8(true) + _p8(true) + _p8(); | |
| } | |
| // to create a GUID, just call it like this: | |
| // var id = CreateGuid(); | |
| // that's it! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment