Created
June 15, 2013 21:44
-
-
Save jagbolanos/5789689 to your computer and use it in GitHub Desktop.
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
/** | |
* Generates a GUID string, according to RFC4122 standards. | |
* @returns {String} The generated GUID. | |
* @example af8a8416-6e18-a307-bd9c-f2c947bbb3aa | |
* @author Slavik Meltser ([email protected]). | |
* @link http://slavik.meltser.info/?p=142 | |
*/ | |
function guid() { | |
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(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment