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