JavaScript/GUID:修订间差异
来自康健生活
创建页面,内容为“ <syntaxhighlight lang="javascript"> function guid() { return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { var r = Math.random() * 16 |…” |
无编辑摘要 |
||
| 第1行: | 第1行: | ||
== GUID == | |||
GUID(Globally Unique Identifier)是UUID的别名;但在实际应用中,GUID通常是指微软实现的UUID。 | |||
<syntaxhighlight lang="javascript"> | <syntaxhighlight lang="javascript"> | ||
2020年5月13日 (三) 15:30的版本
GUID
GUID(Globally Unique Identifier)是UUID的别名;但在实际应用中,GUID通常是指微软实现的UUID。
function guid() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
var r = Math.random() * 16 | 0,
v = c == 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
}
==> "30a58249-cd20-4104-8edc-464c5378dafe"
function guid() {
function S4() {
return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
}
return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4());
}
==> "a2f7ef29-0f17-fbef-78d2-bd6402b3f7b0"
No categories