Created
April 26, 2019 04:44
-
-
Save Mossuru777/747bcbbe7f26b9ea5196bf6d00c96949 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
/** | |
* UUIDv4を作成 | |
* | |
* @see {@link https://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript/2117523#2117523} | |
* @returns {string} UUIDv4の文字列 | |
*/ | |
var generateUUIDv4 = function () { | |
var uuid = ''; | |
for (var i = 0; i < 36; i++) { | |
if (i === 8 || i === 13 || i === 18 || i === 23) { | |
uuid += '-'; | |
} else if (i === 14) { | |
uuid += '4'; | |
} else { | |
var r = Math.random() * 16 | 0; | |
var v = i !== 20 ? r : (r & 0x3 | 0x8); | |
uuid += v.toString(16); | |
} | |
} | |
return uuid; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment