Skip to content

Instantly share code, notes, and snippets.

@Mossuru777
Created April 26, 2019 04:44
Show Gist options
  • Save Mossuru777/747bcbbe7f26b9ea5196bf6d00c96949 to your computer and use it in GitHub Desktop.
Save Mossuru777/747bcbbe7f26b9ea5196bf6d00c96949 to your computer and use it in GitHub Desktop.
/**
* 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