中国优质的IT技术网站
专业IT技术创作平台
IT职业在线教育平台
如何生成一个36位的UUID?
微信扫码分享
/** * 生成36位UUID,带- */ static generateUUID36(): string { const chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split(''); const uuid = new Array<string>(36); let rand = 0; for (let i = 0; i < 36; i++) { if (i === 8 || i === 13 || i === 18 || i === 23) { uuid[i] = '-'; } else if (i === 14) { uuid[i] = '4'; } else { if (rand <= 0x02) { rand = 0x2000000 + (Math.random() * 0x1000000) | 0; } const r = rand & 0xf; rand = rand >> 4; uuid[i] = chars[(i === 19) ? (r & 0x3) | 0x8 : r]; } } return uuid.join(''); }