forked from playcanvas/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathguid.js
More file actions
23 lines (23 loc) · 749 Bytes
/
guid.js
File metadata and controls
23 lines (23 loc) · 749 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/**
* @name pc.guid
* @namespace
* @description Basically a very large random number (128-bit) which means the probability of creating two that clash is vanishingly small.
* GUIDs are used as the unique identifiers for Entities.
*/
pc.guid = function() {
return {
/**
* @function
* @name pc.guid.create
* @description Create an RFC4122 version 4 compliant GUID
* @return {String} A new GUID
*/
create: function() {
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);
});
}
};
}();