Skip to content

Instantly share code, notes, and snippets.

@jagbolanos
Created June 15, 2013 21:44
Show Gist options
  • Save jagbolanos/5789689 to your computer and use it in GitHub Desktop.
Save jagbolanos/5789689 to your computer and use it in GitHub Desktop.
/**
* 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