Guest User

Untitled

a guest
Mar 23rd, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. const charset = '0123456789abcdef'.split('');
  2. const randomset = new Uint8Array(16);
  3.  
  4. export function uuid() {
  5. let rand = 0;
  6. for (let i = 0; i < 16; i++) {
  7. if (rand < 2) {
  8. rand += Math.random() * (1 << 24);
  9. }
  10. randomset[i] = rand & 0xFF;
  11. rand >>>= 8;
  12. }
  13.  
  14. randomset[6] = (randomset[6] & 0x0F) | 0x40;
  15. randomset[8] = (randomset[8] & 0x3F) | 0x80;
  16.  
  17. let output = '';
  18. for (let i = 0; i < 16; i++) {
  19. const rnd = randomset[i];
  20. output += charset[rnd & 15];
  21. output += charset[rnd >>> 4];
  22. }
  23.  
  24. return output;
  25. }
Add Comment
Please, Sign In to add comment