Created
September 27, 2012 14:45
-
-
Save ernestohs/3794397 to your computer and use it in GitHub Desktop.
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
var guid = (function () { | |
var _randomHex = function () { | |
return (((1+Math.random())*0x10000)|0).toString(16).substring(1); | |
}; | |
var _new = function () { | |
var UUID = []; | |
var n = 8; | |
while (n--) { | |
UUID.push(_randomHex()); | |
} | |
return UUID; | |
}; | |
var _toString = function (separator) { | |
var result = _new(); | |
if (separator) | |
{ | |
result = (result[0]+result[1]+"-"+result[2]+"-"+result[3]+"-"+result[4]+"-"+result[5]+result[6]+result[7]) | |
} | |
else | |
{ | |
result = result.join(''); | |
} | |
return result; | |
}; | |
return { | |
toString: _toString | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment