25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

20 lines
633 B

  1. module.exports = function () {
  2. var s = [], itoh = '0123456789ABCDEF';
  3. // Make array of random hex digits. The UUID only has 32 digits in it, but we
  4. // allocate an extra items to make room for the '-'s we'll be inserting.
  5. for (var i = 0; i <36; i++) s[i] = Math.floor(Math.random()*0x10);
  6. // Conform to RFC-4122, section 4.4
  7. s[14] = 4; // Set 4 high bits of time_high field to version
  8. s[19] = (s[19] & 0x3) | 0x8; // Specify 2 high bits of clock sequence
  9. // Convert to hex chars
  10. for (var i = 0; i <36; i++) s[i] = itoh[s[i]];
  11. // Insert '-'s
  12. s[8] = s[13] = s[18] = s[23] = '-';
  13. return s.join('');
  14. }