Skip to content

Latest commit

 

History

History
20 lines (20 loc) · 436 Bytes

2016-01-22-create-guid-uuid-in-javascript.md

File metadata and controls

20 lines (20 loc) · 436 Bytes
id title date author layout guid permalink categories
204
Create GUID / UUID in JavaScript
2016-01-22 18:06:49 +0000
liu1084
post
/?p=204
javascript
function guid() {
  function s4() {
    return Math.floor((1 + Math.random()) * 0x10000)
      .toString(16)
      .substring(1);
  }
  return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4();
}