1function uuid(){
2 var dt = new Date().getTime();
3 var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
4 var r = (dt + Math.random()*16)%16 | 0;
5 dt = Math.floor(dt/16);
6 return (c=='x' ? r :(r&0x3|0x8)).toString(16);
7 });
8 return uuid;
9}
10
11
1function uuidv4() {
2 return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
3 var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
4 return v.toString(16);
5 });
6}
7
8console.log(uuidv4());
1function uuid() {
2 return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
3 var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
4 return v.toString(16);
5 });
6}
7
8var userID=uuid();//something like: "ec0c22fa-f909-48da-92cb-db17ecdb91c5"
1 uuidv4() {
2 return 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
3 var r = (Math.random() * 16) | 0,
4 v = c == 'x' ? r : (r & 0x3) | 0x8;
5 return v.toString(16);
6 });
7 }
1function uuidv4() {
2 return ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g, c =>
3 (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)
4 );
5}
6
7console.log(uuidv4());
1 function uuid() {
2 const template = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx';
3 const xAndYOnly = /[xy]/g;
4
5 return template.replace(xAndYOnly, (character) => {
6 const randomNo = Math.floor(Math.random() * 16);
7 const newValue = character === 'x' ? randomNo : (randomNo & 0x3) | 0x8;
8
9 return newValue.toString(16);
10 });
11 }